3

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!!!

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132

1 Answers1

6

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.

wOxxOm
  • 65,848
  • 11
  • 132
  • 136
  • I got an error: `Unchecked runtime.lastError: Invalid value for origin pattern tabs: Missing scheme separator.` – duXing May 19 '19 at 03:13