gpt4 book ai didi

javascript - firefox 附加 sdk worker.port 事件不起作用

转载 作者:行者123 更新时间:2023-11-28 01:49:35 25 4
gpt4 key购买 nike

又是我:-|

我无法让事件正常工作,我可以将其与worker.port.on(...)一起使用。

查看我的代码:

main.js:

// import the modules we need
var data = require('self').data;
var {Cc, Ci} = require('chrome');
var mediator = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator);
var self = require('self');
var panel = require("sdk/panel");
var ss = require("sdk/simple-storage");
var tabs = require('sdk/tabs');

// exports.main is called when extension is installed or re-enabled
exports.main = function(options, callbacks)
{
tabs.on("ready",
function (activeTab)
{
var worker = activeTab.attach({contentScriptFile: [self.data.url("inject.js")]});
worker.port.on("testmain",
function(data)
{
self.port.emit("testcontent", "bladibla");
}
);
}
);
};

注入(inject).js:

self.port.on("testcontent",
function (data)
{
window.alert(data);
});
self.port.emit("testmain");

如果有帮助就好了。谢谢!

最佳答案

以下调用:

self.port.emit("testcontent", "bladibla");

应该是:

worker.port.emit("testcontent", "bladibla");

关于javascript - firefox 附加 sdk worker.port 事件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19861342/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com