简体   繁体   English

自动运行firefox扩展jpm

[英]Autorun firefox extension jpm

I need help with JPM . 我需要JPM帮助。 I am trying to develop a firefox extension with JPM . 我正在尝试使用JPM开发firefox扩展。 I would like my extension automatically launches when opening firefox, but I can't add an event on the onLoad I know that with the overlay I can do something like : 我希望我的扩展程序在打开firefox时自动启动,但我无法在onLoad上添加事件我知道使用叠加层我可以执行以下操作:

window.addEventListener("load", function load(event){  
    console.log("hello");   
},false);

If I add this event to my JPM extension gives me an error : 如果我将此事件添加到我的JPM扩展名中,则会出现错误:

JPM [error] Message: ReferenceError: window is not defined JPM [error]消息:ReferenceError:未定义窗口

Is it possible to do that with JPM ? JPM可以做到吗? Or is there another way to launch my firefox extension to the opening? 或者是否有另一种方法可以将firefox扩展程序启动到开头?

Your extension already gets loaded when you launch firefox. 启动Firefox时,您的扩展程序已加载。

How do you think the window.addEventListener gets added in the first place? 您如何看待window.addEventListener被添加? It has to execute javascript code to do that. 它必须执行javascript代码才能执行此操作。

@simon, You can also listen for load and unload events. @simon,您还可以监听加载和卸载事件。 https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Listening_for_load_and_unload https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Listening_for_load_and_unload

Therefore, if you add an exports.main = function() {} in index.js, the code inside that function will be run as soon as Firefox starts up and your add-on is loaded. 因此,如果在index.js中添加exports.main = function(){},则只要Firefox启动并加载了加载项,该函数内的代码就会运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM