Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.6k views
in Technique[技术] by (71.8m points)

google chrome extension - Unchecked runtime.lastError while running tabs.executeScript: Cannot access contents of url "data:text/html,chromewebdata"

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
    ]


}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...