2013-09-06 3 views
0

파이어 폭스 android 용 확장 기능을 만들고 있는데 테스트 할 때 제대로 작동합니다. 파이어 폭스를 종료하거나 잠시 사용하지 않으면 확장 기능이 다시 활성화되지 않으면 작동하지 않습니다. 문제는 추가 된 항목 메뉴가 있지만 확장이 작동하지 않습니다 (로드되거나 선택된 페이지의 문서에서 일부 속성을 확인한 다음 요청을 내 localhost에 보냄). 왜 이런 일이 일어나는 지 아십니까? 여기왜 내 파이어 폭스는 안드로이드 확장 기능을 자체적으로 비활성화하나요?

나는 메뉴 항목과 청취자 추가 코드 :

function loadIntoWindow(window) { 
     if (!window) 
     return; 
     if (isNativeUI()) { 
     //adding the items to the menu 
     icoUrl = gAddonData.resourceURI.spec + "iconMenu.png"; //the icon uri 
     var tabAddr=gAddonData.resourceURI.spec+"/content/t.html"; // the uri of a page about the extension 
     //the item opens the page and displays a toast 
      menuIdInfo = window.NativeWindow.menu.add("About TrackDetect",icoUrl, function({  
      window.BrowserApp.addTab(tabAddr); 
      showToast(window); }); 
      // This menu item shows the details collected about the docHTML of currently visited page, these details are brought by the listeners ("TabSelect" and "pageshow") 
      gDoorhangerMenuId = window.NativeWindow.menu.add("Show details ", icoUrl, 
      function(){ //doc is global variable 
     if (doc==null) {window.NativeWindow.toast.show("Please REACTIVATE TrackDetect extension.", "long");} 
      else {showDoorhanger(window, trackersSum);}}); 
      } 
      //adding the listeners 
      window.BrowserApp.deck.addEventListener("TabSelect", function(){ watchTab(window);}, false); 

      let addListener = function() { 
      window.BrowserApp.deck.addEventListener("pageshow", function(){ watchTab(window);}, false); 
      window.NativeWindow.toast.show("Starting to detect trackers.", "long"); 
      }; 

      if(window.BrowserApp.deck) { 
      // BrowserApp.deck has been initialized 
      addListener(); 
      } 
      else { 
      // use the chrome window to wait for BrowserApp to initialize 
      window.addEventListener("UIReady", addListener); 
      } 
      } 

는 사실 내가 오류는 다음과 같습니다

Error: "TypeError: window.BrowserApp.deck is null" 

내가 추가 할 window.BrowserApp.deck 필요를 위의 코드에서와 같은 리스너가 표시됩니다. 그럼, 시작의 메소드를 호출

var windowListener = { 
    onOpenWindow: function(aWindow) { 
    // Wait for the window to finish loading 
    let domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow); 
    domWindow.addEventListener("load", function() { 
     domWindow.removeEventListener("load", arguments.callee, false); 
     loadIntoWindow(domWindow); 
    }, false); 
    }, 

    onCloseWindow: function(aWindow) { 
    }, 

    onWindowTitleChange: function(aWindow, aTitle) { 
    } 
}; 

function startup(aData, aReason) { 
gAddonData = aData; 
setDefaultPrefs(); 
    // Load into any existing windows 
    let windows = Services.wm.getEnumerator("navigator:browser"); 
    while (windows.hasMoreElements()) { 
    let domWindow = windows.getNext().QueryInterface(Ci.nsIDOMWindow); 
    loadIntoWindow(domWindow); 
    } 
Services.scriptloader.loadSubScript(aData.resourceURI.spec + "content/scanner.js", TrackScanner); 
Services.scriptloader.loadSubScript(aData.resourceURI.spec + "content/storageReq.js", TrackReq); 

Services.wm.addListener(windowListener); 
obs.addObserver(httpRequestObserver, "http-on-modify-request", false); 
obs.addObserver(httpResponseObserver, "http-on-examine-response", false); 

try { 
    alertsService.showAlertNotification(gAddonData.resourceURI.spec+"skin/oeil1.png", 
             "TrackDetect activated", "Detecting web Tracking.", 
             false, "", null, ""); 
} catch (e) { 
    // if the extension fail to start 
    alertsService.showAlertNotification("", 
             "Please REACTIVATE Trackdetet", "Please REACTIVATE Trackdetet.", 
             false, "", null, ""); 
} 

if (aReason== ADDON_INSTALL) { 
//some code to set a cookie 
} 

if ((aReason== APP_STARTUP)||(aReason== ADDON_ENABLE)||(aReason== ADDON_UPGRADE)) { 
//some code to get a cookie 
} 
} 

을 그리고 종료에 :

function shutdown(aData, aReason) { 
    if ((aReason == APP_SHUTDOWN) || (aReason == ADDON_DISABLE) || (aReason == ADDON_DOWNGRADE) || (aReason == ADDON_UNINSTALL)) 
    { // code to make sure that the cookie I set is there 
} 

    //cleaning up (removing observers and the window listener) 
    // Stop listening for new windows 
    Services.wm.removeListener(windowListener); 
    obs.addObserver(httpRequestObserver, "http-on-modify-request", false); 
    obs.removeObserver(httpResponseObserver, "http-on-examine-response", false); 

    // Unload from any existing windows 
    let windows = Services.wm.getEnumerator("navigator:browser"); 
    while (windows.hasMoreElements()) { 
    let domWindow = windows.getNext().QueryInterface(Ci.nsIDOMWindow); 
    unloadFromWindow(domWindow); 
    } 
} 

내가 왜 창을 모르기 때문에 지금, 당신은 더 나를 도울 수 있기를 바랍니다. 브라우저를 종료하거나 잠시 사용하지 않으면 BrowserApp.deck이 null이됩니다. 고맙습니다. 청취자

 let addListener = function() { 

창을 추가

// :

+0

코드 및 세부 정보가 없으면 이에 답변 할 수있는 방법이 없으므로 마술 8 개 공을 묻지 마십시오. 질문을 수정하십시오. – nmaier

+0

위의 함수는 확장 기능의 bootstrap.js에있는 시작 함수에서 호출됩니다. 희망이 도움이됩니다. – user2102196

+0

충분하지 않습니다. 작성한 코드 관련 문제는 질문 자체에 특정 문제를 설명하고이를 재현 할 수있는 유효한 코드를 포함해야합니다. 자세한 내용은 http://sscce.org/를 참조하십시오. 콘솔에 오류가 있습니까? – nmaier

답변

0

오류가 tabSelect 이벤트 리스너에 의해 발생하고, 그것이 제대로 작동하도록, 잘못된 장소에서 추가되었다,이했다. BrowserApp.deck.addEventListener ("TabSelect", function() {watchTab (window);}, false); window.BrowserApp.deck.addEventListener ("pageshow", function() {watchTab (window);}, false); window.NativeWindow.toast.show ("추적기 감지 시작 중입니다.", "long"); };

 if(window.BrowserApp.deck) { 
     // BrowserApp.deck has been initialized 
     addListener(); 
     } 
     else { 
     // use the chrome window to wait for BrowserApp to initialize 
     window.addEventListener("UIReady", addListener); 
     } 

물론 이러한 수신기를 나중에 제거했습니다.

관련 문제