无法让 ff 扩展在 v3.0.5 中工作

发布于 2024-10-08 22:43:21 字数 1065 浏览 5 评论 0原文

有谁知道自 v3.0.5 以来可能发生哪些变化才能使扩展正常工作?或者,也许我在某个地方缺少设置?我编写的这个附加组件可以在较新的版本中正常工作,但我无法让它在较旧的版本中启动。具体来说,我什至无法让这部分工作(这是在我的浏览器overlay.xul中):

<html:script>
<![CDATA[

    var Cc = Components.classes;
    var Ci = Components.interfaces;
    var obSvc = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);

    gBrowser.consoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
    gBrowser.log = function(msg){
        this.consoleService.logStringMessage(msg);
    }

    gBrowser.newObj= new MyAddOn();
    gBrowser.log("initializing...");
    function regListener()
    {
        obSvc.addObserver(gBrowser.newObj, "http-on-modify-request", false);
    }
    function unregListener()
    {
        obSvc.removeObserver(gBrowser.newObj, "http-on-modify-request");
    }

    window.addEventListener("load", regListener, false);
    window.addEventListener("unload", unregListener, false);

]]>

这个应该将侦听器附加到新的obj(由链接的.js定义)但是,我什至没有在控制台中收到“正在初始化...”消息。有什么想法吗?

Does anyone know what might have changed since v3.0.5 that would enable extensions to work? Or, maybe I'm missing a setting somewhere? I wrote this add-on that works fine with newer versions, but I can't get it to launch in older ones. Specifically, I can't even get this part to work (this is in my browser overlay.xul):

<html:script>
<![CDATA[

    var Cc = Components.classes;
    var Ci = Components.interfaces;
    var obSvc = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);

    gBrowser.consoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
    gBrowser.log = function(msg){
        this.consoleService.logStringMessage(msg);
    }

    gBrowser.newObj= new MyAddOn();
    gBrowser.log("initializing...");
    function regListener()
    {
        obSvc.addObserver(gBrowser.newObj, "http-on-modify-request", false);
    }
    function unregListener()
    {
        obSvc.removeObserver(gBrowser.newObj, "http-on-modify-request");
    }

    window.addEventListener("load", regListener, false);
    window.addEventListener("unload", unregListener, false);

]]>

This should attach listeners to the new obj (defined by a linked .js) However, I'm not even getting the "initializing..." message in the console. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薆情海 2024-10-15 22:43:21
  1. 不要使用,使用
  2. 不要从窗口叠加层注册应用程序全局侦听器 (http-on-modify-request)。这样做将使您的代码在用户可能打开的每个窗口中运行一次。使用 XPCOM 组件 - https://developer.mozilla.org/en/Setting_HTTP_request_headers
  3. 不要用您自己的属性污染公共对象(例如 gBrowser 或全局对象(使用 var Cc))。如果每个人都这样做,那么两个扩展就不会一起工作。将所有代码属性放在您自己的对象上并使用唯一的名称。
    • 在加载事件之前访问 gBrowser 可能是导致您出现特定问题的原因。
  4. 设置您的环境并检查错误控制台以调试问题。
  5. 不要浪费时间尝试支持 Firefox 3。Mozilla 本身已经一年多不支持它了,不应该用它来访问网络。
  1. Don't use <html:script>, use <script> (assuming you have xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" on your root <overlay> element).
  2. Don't register an application-global listener (http-on-modify-request) from a window overlay. Doing so will make your code run one time in each window the user may have open. Use an XPCOM component instead - https://developer.mozilla.org/en/Setting_HTTP_request_headers
  3. Don't pollute common objects (like gBrowser or the global object (with var Cc)) with your own properties. If everyone did that, no two extensions would work together. Put all your code properties on your own object with a unique name.
    • accessing gBrowser before the load event is probably what's causing your specific problem.
  4. Set up your environment and check the Error Console to debug problems.
  5. Don't waste time trying to support Firefox 3. It's not supported by Mozilla itself for over a year and shouldn't be used to access the web.
橘寄 2024-10-15 22:43:21

看起来 gBrowser.log 未定义,或者至少不是函数,错误控制台可能会告诉您。我也从未听说过。也许它是在 Fx 3.5 中添加的?

It looks like gBrowser.log is not defined, or at least is not a function, as the error console will probably tell you. I've never heard of it either. Maybe it was added in Fx 3.5?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文