错误处理响应:TypeError:在chrome-extension中无法读取未定义的属性“ show”

时间:2020-08-21 21:28:53

标签: javascript google-chrome-extension manifest.json

在contentScript.js上,我放了这段代码...

chrome.runtime.sendMessage({ todo: "showPage" });

和backgroundScript.js

chrome.runtime.onMessage.addListener(function(request, sender, senderResponse) {
  if (request.todo == "showPage") {
    chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
      chrome.pageAction.show(tabs[0].id);
    });
  }
});

这是manifest.json文件

{
  "manifest_version": 2,
  "name": "Startpage Chrome Extension",
  "description": "The extension will replace/load additional CSS and override Startpage default style, it should look exactly (or almost) like Google.",
  "version": "1.0.1",
  "author": "OpenText",
  "content_scripts": [
    {
      "matches": ["*://*.google.com/*"],
      "all_frames": true,
      "js": ["./jquery.js", "./startpage.js"],
      "css": ["startpage.css"],
      "run_at": "document_start"
    }
  ],
  "background": {
    "scripts": ["./jquery.js", "background.js"],
    "persistent": false
  },
  "icons": {
    "16": "icon.png",
    "48": "icon.png",
    "128": "icon.png"
  },
  "offline_enabled": true,
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html",
    "default_title": "Startpage Extension"
  },
  "permissions": ["tabs", "activeTab", "storage", "*://www.google.com/*"]
}

这是我得到的错误:“错误处理响应:TypeError:无法读取chrome-extension://phgdcficdbmcpddkligkfkjjcognioik/background.js:17:25中未定义的属性“ show”

enter image description here

1 个答案:

答案 0 :(得分:1)

只需将 **Inventory Model** func showStockList_byStockQuantity() -> [StockModel] { let allStocks = self.ofStock.sorted(byKeyPath: "name", ascending: true).distinct(by: ["name"]) var activeStocks:[StockModel] = [] for stock in allStocks.enumerated() { let stockQuantity:Int = realm!.objects(StockModel.self).filter("name == %@", stock.element.name).sum(ofProperty: "quantity") if stockQuantity > 0 { activeStocks.append(stock.element) } } return activeStocks } 中的“browser_action”更改为“page_action”。