3

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
    ]


}
Community
  • 1
  • 1
user5858
  • 1,082
  • 4
  • 39
  • 79
  • Have you tried following Haibara Ai's [answer](http://stackoverflow.com/questions/36762389/chrome-extension-injecting-script-get-error)? `chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { for(var i = 0; i – Mr.Rebot May 08 '16 at 13:21
  • @user5858, could you please post the entire `manifest.json` file? And which page do you want your `showbacklink.js` to be injected in? – Haibara Ai May 10 '16 at 09:39
  • @HaibaraAi I want to inject the code with `showbacklink.js` into the content script or the web page – user5858 May 10 '16 at 10:35
  • Hooking https://stackoverflow.com/q/31051387/632951 and https://stackoverflow.com/q/32761782/632951 – Pacerier Aug 10 '17 at 04:31
  • Btw for handling lastErrors, use https://stackoverflow.com/a/45603880/632951 – Pacerier Aug 10 '17 at 04:33

1 Answers1

4

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.

Xan
  • 74,770
  • 16
  • 179
  • 206
  • During this error I want to provide them a link which they should click to restart to step-1. At the moment I've added this link in the popup but the users will need to click on the options icon. – user5858 May 10 '16 at 11:31
  • If you have a link and you display some replacement error page, you can use that link there. – Xan May 10 '16 at 11:45
  • You mean redirecting a page to some custom page? That I want to avoid as original error/problem may be lost from user's sight. Best should be to insert a link in the error page so that user can be aware of error and possible click the remedy link immediately. – user5858 May 11 '16 at 14:43
  • 1
    What you ask for is not possible in any circumstances. – Xan May 11 '16 at 14:56
  • @Xan, Data:text/html are used for other things too, not just chrome internal webpages. – Pacerier Aug 06 '17 at 07:38
  • @Xan, Sigh, they're fixing all the stuff that no one needs yet leave important ones used by [⨕ the commoners](https://groups.google.com/a/chromium.org/forum/#!topic/chromium-extensions/-CfZ-wO0Wsw) unfixed. – Pacerier Oct 13 '17 at 02:10