无法在Chrome扩展API中将脚本执行到新标签中

时间:2019-03-02 23:04:27

标签: javascript google-chrome-extension

使用window.location.href= $newURL打开新标签后,我试图运行executeScript

错误:

Unchecked runtime.lastError: Cannot access contents of url "https://www.google.com/_/chrome/newtab?ie=UTF-8". Extension manifest must request permission to access this host.

manifest.json仍需要添加什么权限

{
    "name": "Getting Started Example",
    "version": "1.0",
    "description": "Build an Extension!",
    "manifest_version": 2,
    "background": {
      "scripts": ["background.js"],
      "persistent": false
    },
    "permissions": ["activeTab", "tabs", "declarativeContent", "*://*/*", "storage"],
    "page_action": {
        "default_popup": "popup.html"
    }
  }

以及background.js

中新标签的运行代码
chrome.runtime.onInstalled.addListener(function() {
   chrome.tabs.onCreated.addListener(function( tab ){
     tab.url = "https://mahmoudzakaria90.github.io/HelloZeka/public/"
     chrome.tabs.executeScript({
        file: './inject.js'
     })
   })
   chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
      chrome.declarativeContent.onPageChanged.addRules([{
        conditions: [new chrome.declarativeContent.PageStateMatcher()
        ],
            actions: [new chrome.declarativeContent.ShowPageAction()]
      }]);
    });
 });

0 个答案:

没有答案