Unchecked runtime.lastError while running tabs.executeScript: Cannot access contents of url “data:text/html,chromewebdata”

瘦欲@ 提交于 2020-01-11 10:10:49

问题


I'm getting this error:

extensions::lastError:133 Unchecked runtime.lastError while running tabs.executeScript: Cannot access contents of url "data:text/html,chromewebdata". Extension manifest must request permission to access this host.

I'm getting this error after disabling internet so that I can take action when the page load fails(due to heavy load) or internet down.

I've checked all similar questions and this almost similar but still unable to make it work. Another very similar one with comment that Chrome does not allow hijack of internal pages

My permissions looks like:

"permissions": [
        "tabs","unlimitedStorage", "notifications", "history", "activeTab", "storage", "webRequest", "webRequestBlocking", "*://*/*", "http://*/*", "https://*/*"
    ],

I get the error when I run this code:

chrome.tabs.executeScript(null, {file: "showbacklink.js"});

or

  chrome.tabs.executeScript(details.tabId, {file: "showbacklink.js"});

where details.tabId is the active tab.

What am I missing?

Edited manifest.json

{
    "name": "",
    "options_page": "options.html",
    "description": "",
    "version": "1.0",
    "icons": {
        "16": "icons/logo16.png",
        "48": "icons/logo48.png",
        "128": "icons/logo128.png"
    },
    "permissions": [
        "tabs","unlimitedStorage", "notifications", "history", "activeTab", "storage", "webRequest", "webRequestBlocking",  "http://*/*", "https://*/*"
    ],
    "background": {
        "scripts": [
        "showbacklink.js",
            "client_server_common.js",
            "common.js",
            "background.js"

        ],
        "persistent": true
    },

    "content_security_policy": "script-src 'self'; object-src 'self'",
    "manifest_version": 2,
    "content_scripts": [
        {
            "run_at": "document_end",
            "all_frames": true,
            "matches": ["https://*/*"],
            "css": [//REMOVED],
            "js": [   //other files REMOVED
                "myscript.js",

            ]
        },


    ],
    "web_accessible_resources": [  //REMOVED
    ]


}

回答1:


Indeed, the "Offline" page, or any other error page shown is treated as a Chrome internal page instead of its "original" URL. As such, you can't inject into such pages to change them for security reasons. Imagine for a moment that an extension would be able to interact with SSL warning pages - you really, really don't want that.

If your goal is to provide some sort of alternative error page, you need to hook a listener for such navigation errors and redirect to your own page.

I would recommend looking at webNavigation and webRequest API.



来源:https://stackoverflow.com/questions/37093152/unchecked-runtime-lasterror-while-running-tabs-executescript-cannot-access-cont

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