Unchecked runtime.lastError: Cannot access a chrome:// URL

11,961 views
Skip to first unread message

peter black

unread,
May 15, 2019, 10:14:21 AM5/15/19
to Chromium Extensions
In Google chrome extension, background.js's execute script isn't load file.

background.js

chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
    
    chrome.tabs.executeScript(tabId, {
        file: 'index.js'
    });
});


manifest.json

{
    "manifest_version": 2,
    "permissions": [
        "activeTab",
        "declarativeContent",
        "storage",
        "tabs",
        "file://*/*",
        "https://*/*",
        "http://*/*"
    ],
    "background": {
        "scripts": ["js/jquery.min.js", "js/background.js"],
        "persistent": true
    },
    "content_security_policy": "script-src 'self' https://ssl.google-analytics.com; object-src 'self'"
}

Errors are,<br>
1. Unchecked runtime.lastError: Cannot access a chrome:// URL <br>
2. Unchecked runtime.lastError: Failed to load file: "index.js".<br>
3. Unchecked runtime.lastError: Cannot access contents of url "chrome-search://local-ntp/local-ntp.html". Extension manifest must request permission to access this host.

peter black

unread,
May 20, 2019, 9:11:08 AM5/20/19
to Chromium Extensions
Is there anyone can solve this issue.

wOxxOm

unread,
May 21, 2019, 11:16:15 AM5/21/19
to Chromium Extensions
You've already asked the same question on StackOverflow a week ago. It's not clear what you want to achieve, but as I commented there, you can suppress the error by simply accessing chrome.runtime.lastError in the callback:

    chrome.tabs.executeScript(tabId, {
        file: 'index.js'
    }, () => chrome.runtime.lastError);

wOxxOm

unread,
May 21, 2019, 11:28:49 AM5/21/19
to Chromium Extensions
In case you want to run your js file on the new empty tab page, it's intentionally forbidden by Chrome so you can't do that. Instead, you'll have to provide an entire new tab page via the chrome_url_overrides mechanism. See also the demo extensions.

Santiago San Martin

unread,
Feb 7, 2021, 7:57:20 AM2/7/21
to Chromium Extensions, wOxxOm
this message is translated with google Thank you very much. You are a genius. I was trying to solve that problem and could not find the solution anywhere. thank you bonnet thank you very much
Reply all
Reply to author
Forward
0 new messages