我已经在整个文档中进行了挖掘,但是我无法找到如何使用 self.qleTextBoxCam1Focus.editingFinished.connect(self.qleCam1Focus)
打开长期连接的示例或说明。我想要做的是每次创建选项卡时,我都会打开与该选项卡的长期连接。我想跟踪信息来自哪个标签。这就是我所拥有的:
background.js
chrome.tabs.connect
的script.js
/*CREATING AND STORING A PORT FOR INDIVIDUAL TABS*/
chrome.tabs.onCreated.addListener(function(tab) {
/*SETTIMEOUT BECAUSE CONNECTING RIGHT AWAY DOESN'T REGISTER*/
setTimeout(function() {
var port = chrome.tabs.connect(tab.id, {name: tab.id.toString()});
/*SAVE EACH PORT IN AN ARRAY*/
portsMod.addPort(port);
/*TESTING RECEIVING MESSAGES FROM CONTENT SCRIPT ON EACH INDIVIDUAL PAGE*/
port.onMessage.addListener(function(msg) {
console.log("CAME FROM " + msg.portNum + " " + msg.timesSent + " TIMES.");
});
}, 1000);
});
我重新加载扩展程序并打开一堆标签。它有效,但滞后。我得到它最多15个选项卡,但它是滞后的(例如,我会得到一个日志条目,然后7个,然后其余的一次)。这真的是一种正确的做法吗?还是有更好的方法?