如何检测扩展中的页面加载错误
How to detect page loading error from extension?
有没有办法检测选项卡是否显示"错误页面"?
我的意思是,例如,如果用户输入任何 http://non-existing-url.com 或只是网站不可用。
任何类似于Chrome的webNavigation.onErrorHappened事件。
如果没有类似的事件,也许有一种方法可以检查 Tab http 状态(200、404、502、0 等)?
哎呀没有看到这个话题。这是你可以怎么做,寻找关于:网络错误加载
来自: MozillaZine :: 检测火狐浏览器中的"加载页面问题"
必须通过浏览器的Web导航来阅读文档。
无论如何,当发生错误时,docuri真的很好。 它清楚地告诉您 e 参数中的问题。这些是一些加载的 docuris 的示例:
about:neterror?e=dnsNotFound&u=http%3A//www.cu.reporterror%28%27afew/&c=UTF-8&d=Firefox%20can%27t%20find%20the%20server%20at%20www.cu.reporterror%28%27afew.
about:neterror?e=malformedURI&u=about%3Abalk&c=&d=The%20URL%20is%20not%20valid%20and%20cannot%
你可以看到第一个是dnsNotFound,第二个是格式错误的URI
var listenToPageLoad_IfProblemLoadingPage = function(event) {
var win = event.originalTarget.defaultView;
var webnav = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation);
//console.log('webnav:', webnav, 'webnav of selectedtab:', window.gBrowser.webNavigation);
var docuri = webnav.document.documentURI; //can also try event.originalTarget.linkedBrowser.webNavigation.document.documentURI <<i didnt test this linkedBrowser theory but its gotta be something like that
var location = win.location + ''; //I add a " + ''" at the end so it makes it a string so we can use string functions like location.indexOf etc
if (win.frameElement) {
// Frame within a tab was loaded. win should be the top window of
// the frameset. If you don't want do anything when frames/iframes
// are loaded in this web page, uncomment the following line:
// return;
// Find the root document:
//win = win.top;
if (docuri.indexOf('about:neterror') == 0) {
Components.utils.reportError('IN FRAME - PROBLEM LOADING PAGE LOADED docuri = "' + docuri + '"');
}
} else {
if (docuri.indexOf('about:neterror') == 0) {
Components.utils.reportError('IN TAB - PROBLEM LOADING PAGE LOADED docuri = "' + docuri + '"');
}
}
}
window.gBrowser.addEventListener('DOMContentLoaded', listenToPageLoad_IfProblemLoadingPage, false);
相关文章:
- jQuery:获取图像加载错误的详细信息
- Html抓取网站加载错误的J汤Java
- 这是 Opera 中的加载错误吗?
- 角度模块加载错误
- lightgallery type未加载错误图像
- 从URL获取JSON文件,XMLHttpRequest无法加载错误
- jQuery 加载错误的值
- Chrome 49 定时和使用 require.js 模块的加载错误
- 主干木偶:木偶.应用程序导致 Require.js 模块加载错误,“'错误:尚未为上下文加载模块名称'A
- 如何捕获 iframe 加载错误
- 间歇性要求JS加载错误
- JQuery Mobile - 关闭对话框后加载错误的页面,并且Javascript并不总是有效
- Android “SQLite 数据库无法从 /CachedGeoposition.db 加载”错误,尝试从 webvi
- Requirejs 忽略可选依赖项的加载错误
- EOF / 使用 AJAX 调用 PHP 文件时无法加载错误
- 为什么这个图像访问加载错误在承诺脚本小提琴上
- 浏览器加载错误仅具有特定文件路径 - 内部服务器错误 500
- 如何检测扩展中的页面加载错误
- Angularjs html5Mode(true) 页面重新加载错误与 Node.js 服务器
- “加载错误:未知”时尝试在 Javascript SDK 中删除 apprequest