2014-11-20 2 views
3

탭에 '오류 페이지'가 표시되는지 감지하는 방법이 있습니까?확장 프로그램에서 페이지 로딩 오류를 감지하는 방법은 무엇입니까?

예를 들어 사용자가 http://non-existing-url.com을 입력하거나 사이트를 사용할 수없는 경우를 예로들 수 있습니다.

Chrome의 webNavigation.onErrorOccured 이벤트와 비슷한 항목입니다.

비슷한 이벤트가 없다면 아마도 탭 http 상태 (200, 404, 502, 0, 등 ...)를 확인할 수있는 방법이 있을까요?

+0

내가 생각할 수있는 유일한 해결책은 병렬 [을 확인하는 것입니다 첫 번째는 dnsNotFound이고, 두 번째는 볼 수 theese는 부하 docuris 몇 가지의 예 요청] (https://developer.mozilla.org/ko-KR/Add-ons/SDK/High-Level_APIs/request)을 방문하여 응답이 무엇인지 확인한 다음 중복 요청을하면 느낄 수 있습니다 느린 연결에서. – willlma

답변

1

위생병은이 주제를 보지 못했습니다. 다음은이 약을 찾아 할 수있는 방법은 다음과 같습니다 mozillaZine :: Detecting “problem loading page” in firefox

브라우저의 webNavigation을 통해 docuri을 읽을 수 있습니다에서 neterror로드

. window.location이 다르기 때문에

어쨌든 docuri는 오류가 발생했을 때 정말 멋지다. e 매개 변수에서 문제가 무엇인지 분명하게 알려줍니다.

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%

당신이 malformedURI

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); 
+0

감사합니다! BTW, 아마 FF 탭에 대한 간단한 HTTP 상태를 감지하는 방법을 알고 있을까요? (404 또는 502 등 ...) – norlin

+0

@norlin 그것은 좋은 질문입니다, 나는 내 머리 꼭대기에서 잘 모릅니다. 그러나 나는 나중에 둘러 볼 수 있으며, anoter 질문을 게시 할 수 있습니다. :) – Noitidart

+0

감사합니다. 이미 [Observer Notifications] (https://developer.mozilla.org/en/US/docs/Observer_Notifications)를 통해 방법을 찾았습니다. – norlin

관련 문제