检测FF添加中的导航 [英] Detecting navigation in FF add ons

查看:148
本文介绍了检测FF添加中的导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用FF Addon SDK将Chrome扩展程序移植到FF。在后台脚本(main.js)文件中,我需要使用FF相当于...

  chrome.webNavigation。 onBeforeNavigate.addListener()

  chrome.tabs.onUpdated.addListener()

我注意到require(sdk / tabs)。只有打开,关闭,完成等,但与导航无关。



我看到几个解决方案使用Page-Mod或者显示用于开发FF扩展的旧XUL方法的解决方案。



编辑:我能够通过使用Progress Listener找出chrome.tabs.onUpdated.addListener()的替代方法。显然,在FF中它被称为onLocationChange。还在寻找chrome.webNavigation.onBeforeNavigate.addListener()的替代方法。

解决方案

好的,我设法弄清楚了。我们需要使用onStateChange监听器。为了模仿onBeforeNavigation,我们不仅需要检查STATE_START,还需要检查STATE_IS_DOCUMENT。
$ b $ $ $ $ $ $ p $ var $ progressListener = {
QueryInterface :XPCOMUtils.generateQI([Ci.nsIWebProgressListener,Ci.nsISupportsWeakReference]),

onLocationChange:function(aWebProgress,aRequest,aURI){
if(aRequest&& aURI){
console.log('onLocationChange:'+ aURI.spec);


$ b $ onStateChange:function(aWebProgress,aRequest,aStateFlags,aStatus){
var status = Ci.nsIWebProgressListener; (aStateFlags& status.STATE_START&&& aStateFlags& status.STATE_IS_DOCUMENT){
console.log('onStateChange:'+ aRequest.QueryInterface(Ci.nsIChannel).originalURI(

)。规范);
}
}
};


I am porting a Chrome extension to FF using 'FF Addon SDK'. In the background script (main.js) file, I need to use the FF equivalent of...

chrome.webNavigation.onBeforeNavigate.addListener()

and

chrome.tabs.onUpdated.addListener()

I noticed that require("sdk/tabs").on only has open, close, finish, etc., but nothing to do with the navigation.

I see a few solutions that use Page-Mod or show the solution for the old XUL way of developing FF Extensions. I am specifically looking for an FF Addon SDK (only) solution.

Appreciate any inputs.

EDIT: I was able to figure out an alternative for chrome.tabs.onUpdated.addListener() by using Progress Listener. Apparently, in FF it is called onLocationChange. Still looking for an alternative to chrome.webNavigation.onBeforeNavigate.addListener()

解决方案

OK, I managed to figure it out. We need to use the onStateChange listener. To mimic onBeforeNavigation, we need to not only check for STATE_START, but also STATE_IS_DOCUMENT.

var progressListener = {
    QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener, Ci.nsISupportsWeakReference]),

    onLocationChange: function(aWebProgress, aRequest, aURI) {
        if (aRequest && aURI) {
            console.log('onLocationChange: ' + aURI.spec);
        }
    },

    onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) {
        var status = Ci.nsIWebProgressListener;

        if(aStateFlags&status.STATE_START && aStateFlags&status.STATE_IS_DOCUMENT) {
            console.log('onStateChange: ' + aRequest.QueryInterface(Ci.nsIChannel).originalURI.spec);
        }
    }
};

这篇关于检测FF添加中的导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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