Access extensions in the chrome://extensions page [duplicate]

微笑、不失礼 提交于 2020-01-21 09:06:33

问题


Here is my mainfest.json:

"content_scripts": [ {
    "all_frames": true,
    "css": [ "css/event.css" ],
    "matches": [ "\u003Call_urls>" ],
    "run_at": "document_start"
}

but I cannot find content script in the chrome://extensions/ page
help!!!


回答1:


You can do it on your PC by enabling chrome://flags/#extensions-on-chrome-urls and adding the necessary url, chrome://extensions/, into "matches" in manifest.json but such extension won't be possible to install on a normal browser due to an invalid scheme error.

To avoid the fatal error, don't use manifest.json to inject the content script/style, do it manually in the background or popup script via chrome.tabs.insertCSS or chrome.tabs.executeScript:

  • chrome://flags: enable Extensions on chrome:// URLs flag
  • manifest.json:

    "permissions": ["chrome://*/*", "tabs"],
    "background": {
        "scripts": ["background.js"]
    },
    
  • 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
                    });
                }
            });
        }
    });
    

Beware of possible problems submitting such extension to the Chrome Webstore.



来源:https://stackoverflow.com/questions/33891245/access-extensions-in-the-chrome-extensions-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!