Managing the page "Oops! Chrome could not be found ..."?

When you enter the wrong address, Chrome displays a gray page that says: "Unfortunately, Google Chrome could not find X. Did you mean Y?"

Since this is not an HTTP page, but one of the functions built into the browser, I can’t put the contents of the script in it and I can’t control it, so my extension is frozen until the user manually goes to another page.

Since the extension should be able to independently control the browser, it is very important that at any time when this page opens, it automatically returns to the page on which I have access to the content of the script, and then a message is displayed instead.

It's impossible?

+2
source share
2 answers

You can use chrome.webNavigation.onErrorOccurredto detect such errors and redirect to another page if you want. If you have no reason for this, I highly recommend recommending against implementing such a function, as this may violate users' expectations about how the browser works.

However, a sample code:

chrome.webNavigation.onErrorOccurred(function(details) {
    if (details.frameId === 0) {
        // Main frame
        chrome.tabs.update(details.tabId, {
            url: chrome.runtime.getURL('error.html?error=' + encodeURIComponent(details.error))
        });
    }
});
+3
source

According to the documents, the only pages that can be overridden are:

  • Bookmark manager
  • Story
  • New tab

Thus, the extension cannot change / contol / affect the behavior of the browser relative to the page "Oops! ...".

+1

Source: https://habr.com/ru/post/1541036/


All Articles