0

I'm building an Chrome Extension Manifest Version 3.

I get this error when I try installing it.

Here are the important parts of my manifest.json:

    "permissions": ["storage", "tabs", "identity", "scripting"],
    "host_permissions": ["<all_urls>"],
    "content_scripts": [
        {
            "matches": ["http://*/*", "https://*/*"],
            "js": ["scripts/contentScript.js"],
            "css": ["css/content.css"],
            "run_at": "document_end"
        }
    ]

and here is my service worker code:

chrome.runtime.onInstalled.addListener(() => {
    chrome.tabs.query({}, tabs => {
        for (const tab of tabs) {
            if (tab.url && isSupportedURL(tab.url)) {
                chrome.scripting.executeScript({
                    target: { tabId: tab.id },
                    files: ['scripts/contentScript.js'],
                });
                chrome.scripting.insertCSS({
                    target: { tabId: tab.id },
                    files: ['css/content.css'],
                });
            }
        }
    });
});

function isSupportedURL(url) {
    return url.startsWith('http') && !url.startsWith('https://chrome.google.com/webstore');
}
kecman
  • 813
  • 3
  • 14
  • 34
  • Please remove `service worker` . – Norio Yamamoto Jun 15 '23 at 03:15
  • but I need it in order to inject contentScript.js and content.css into tabs that were open before extension was installed – kecman Jun 15 '23 at 03:21
  • Your code is correct and makes perfect sense, so there are two explanations: 1) you're seeing an old error in the retarded chrome://extensions UI (just click the trashcan or `clear all` button), 2) check `chrome://policy` for ExtensionSettings that contains `runtime_blocked_hosts` and if it does the only thing you can do is suppress the error by adding `.catch(() => {})` to both methods. – wOxxOm Jun 15 '23 at 06:19
  • @kecman, I see. If the error is harmless, it should be ignored. – Norio Yamamoto Jun 15 '23 at 07:11
  • @wOxxOm to which methods should I add catch? I tried adding it to every method but error still shows up. – kecman Jun 15 '23 at 20:35
  • To executeScript and insertCSS. Also see the note about the retarded chrome://extensions UI. – wOxxOm Jun 15 '23 at 21:27
  • adding catch to executesript and insertCSS doesn't prevent the error from showing up – kecman Jun 21 '23 at 10:08

0 Answers0