控制“糟糕! Chrome无法找到...“页? [英] Controlling the "Oops! Chrome could not find ... " page?

查看:119
本文介绍了控制“糟糕! Chrome无法找到...“页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您输入无效地址时,Chrome会显示一个灰色页面,指出糟糕!谷歌浏览器无法找到X.您的意思是Y吗?



因为这不是一个HTTP页面,而是浏览器内置的东西之一,我不能在其中放置内容脚本并且无法控制它,所以我的扩展程序被冻结,直到用户手动进入其他页面。



由于扩展名应该能够独立控制浏览器,因此在此页面打开的任何时候,它都会自动返回到我执行的页面 有内容脚本访问权限,然后显示一条消息。 >解决方案

您可以使用 chrome.webNavigation.onErrorOccurred 检测此类错误,如果需要,可重定向到其他页面。除非您有足够的理由这样做,否则我强烈建议实施此类功能,因为它可能会破坏用户对浏览器行为方式的期望。



然而,示例代码:


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


When you type in an invalid address, Chrome displays a grey page that says "Oops! Google Chrome could not find X. Did you mean Y?"

Because this is not an HTTP page but rather one of the browser's built-in things, I can't put a content script in it and can't control it, so my extension is frozen until the user manually goes to another page.

Since the extension is supposed to be able to control the browser on its own, it's very important that anytime this page opens, it automatically goes back to a page I do have content script access to, and then displays a message instead.

Is this impossible?

解决方案

You can use the chrome.webNavigation.onErrorOccurred to detect such errors, and redirect to a different page if you want. Unless you've got an extremely good reason to do so, I strongly recommend against implementing such a feature, because it might break the user's expectations of how the browser behaves.

Nevertheless, 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))
        });
    }
});

这篇关于控制“糟糕! Chrome无法找到...“页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆