chrome:// extensions页面中的访问扩展

迎风尿*_*尿十丈 2 javascript google-chrome-extension

这是我的mainfest.json

"content_scripts": [ {
    "all_frames": true,
    "css": [ "css/event.css" ],
    "matches": [ "\u003Call_urls>" ],
    "run_at": "document_start"
}
Run Code Online (Sandbox Code Playgroud)

但我无法在chrome://extensions/页面
帮助中找到内容脚本!!!

wOx*_*xOm 5

您可以通过启用做你的电脑上chrome://flags/#extensions-on-chrome-urls,并添加必要的网址,chrome://extensions/"matches"manifest.json中,但这种扩展将无法安装在普通的浏览器由于无效方案的错误。

为避免致命错误,请不要使用manifest.json注入内容脚本/样式,而是通过chrome.tabs.insertCSS或在后台或弹出脚本中手动进行操作chrome.tabs.executeScript

  • chrome://flags:启用Extensions on chrome:// URLs标志
  • manifest.json:

    "permissions": ["chrome://*/*", "tabs"],
    "background": {
        "scripts": ["background.js"]
    },
    
    Run Code Online (Sandbox Code Playgroud)
  • background.js:

    var chromeURLstylable;
    chrome.permissions.contains({origins: ["chrome://*/*"], permissions: ["tabs"]}, function(state) {
        chromeURLstylable = state;
        console.log("chrome:// urls support", state);
    
        if (chromeURLstylable) {
            chrome.tabs.onUpdated.addListener(function(tabId, info, tab) {
                if (info.status == "loading" && tab.url.indexOf("chrome://") == 0) {
                    chrome.tabs.insertCSS({
                        file: "style.css", 
                        runAt: "document_start",
                        allFrames: true
                    });
                }
            });
        }
    });
    
    Run Code Online (Sandbox Code Playgroud)

提防将此类扩展名提交到Chrome Webstore时要小心。