I have simple Firefox extension (based on Add-on SDK) with pageMod
.
pageMod
injects some script to a page, which calls one function:
function dispatchEvent(name, data){
try {
data = data || {};
// passing some data through html element
document.getElementById( MyDiv ).innerText = JSON.stringify(data);
var evt = document.createEvent( Event );
evt.initEvent(name.toString(), true, true);
if(document.getElementById( MyDiv ).dispatchEvent(evt))
console.log("Dispatch event: "+name+" data: "+JSON.stringify(data));
} catch (e) {
console.log("Error:" + e);
}
}
dispatchEvent("MyEvent", {});
On the web page I have event listener, added through MyDiv.addEventListener(...)
.
Problem is the injected script does not dispatch any event to a page. The dispatchEvent
function returns true, but nothing happens.
Here is my pageMod
code:
var myMod = pageMod.PageMod({
include: ["http://localhost/mysite/*"],
contentScriptFile: [data.url("js/script.js")],
contentScriptWhen: "end",
onAttach: function onAttach(worker) {
console.log("CS injected");
}
});
如果Impcontent texts
守则通过Pabug console进行,但我需要从<条码>发送活动。
P.S.,我还试图使用<代码>unsafeWindow.document而不是文件,并利用j Query活动/event 听众,并且不工作。