Nw.js: Chrome error pages override

Created on 27 May 2016  路  7Comments  路  Source: nwjs/nw.js

@rogerwang do you plan any way to override the default chrome error pages/messages (like this one: http://code2care.org/pages/resolving-dns_probe_finished_nxdomain-google-chrome-error/images/DNS_PROBE_FINISHED_NXDOMAIN%20Error%20Message.png) with custom app error pages.

It could be a good feature to let the app look like a native app (and not a well known browser)

Thank you

Most helpful comment

@rogerwang @iteufel
It doesn't work with nw.js 0.17.6 (there is no iframe) and even trying to replace DOM inside the event callback there is no possibility to do it.

I even tested this solution : http://stackoverflow.com/questions/14841256/change-chrome-4xx-page

chrome.webNavigation.onErrorOccurred.addListener(function (details) {
    // Updating the browser window with desired URL
    chrome.tabs.update(details.tabId, {
        url: chrome.extension.getURL("page.html")
    });
});

but on redirect I get chrome-extension:// invalid error ( Resources must be listed in the web_accessible_resources manifest key ) so I get a loop because of the redirect error.

Do I need to set my custom error page inside allowed resources? This is already a local resource.
I can't find a way to do what on chrome we do with:

"web_accessible_resources": [
        "page.html"
    ]

Any other way to accomplish it?
Thank you

All 7 comments

Yeah. I'll try to support it. Thanks.

@AndryBray you can try chrome.webRequest.onErrorOccurred

chrome.webRequest.onErrorOccurred.addListener(function (details) {
    document.getElementsByTagName("iframe")[0].src = "my_error_page"
},  {urls: ["<all_urls>"]})

Thanks. @iteufel 's answer should be the solution.

@rogerwang @iteufel
It doesn't work with nw.js 0.17.6 (there is no iframe) and even trying to replace DOM inside the event callback there is no possibility to do it.

I even tested this solution : http://stackoverflow.com/questions/14841256/change-chrome-4xx-page

chrome.webNavigation.onErrorOccurred.addListener(function (details) {
    // Updating the browser window with desired URL
    chrome.tabs.update(details.tabId, {
        url: chrome.extension.getURL("page.html")
    });
});

but on redirect I get chrome-extension:// invalid error ( Resources must be listed in the web_accessible_resources manifest key ) so I get a loop because of the redirect error.

Do I need to set my custom error page inside allowed resources? This is already a local resource.
I can't find a way to do what on chrome we do with:

"web_accessible_resources": [
        "page.html"
    ]

Any other way to accomplish it?
Thank you

I'm also trying to replace the default Chrome error pages (for usage within Chrome webview) with something custom, but I can't get it to work.
I tried chrome.webRequest/webNavigation.onErrorOccurred but these event are not called.
I think maybe that's because I have a Chrome Apps webview in which the page is loaded. _(edit: confirmed, I added onCompleted and works for the resources within the apps itself.)_

So I tried the loadabort event of the webview. This one is actually triggering but only after the Chrome error page is shown and when the user click on the back button which is on the Chrome error page. So this is too late.

Any ideas?

Maybe my comment on this related issue will be helpful for you:
https://github.com/nwjs/nw.js/issues/5365

@AndryBray Your code helped me create my first chrome extension. Thanks very much.

Was this page helpful?
0 / 5 - 0 ratings