Answer the question
In order to leave comments, you need to log in
Chrome extensions. Persistently open chrome.tabs.connect() port. How?
Hi Dear! Straight to the point. in my extension for Google Chrome, I need a permanently open port for popup.html communication (that is, the part that appears when you click on the extension icon in the manifest is “default_popup”) and the part that works directly on the tab itself (the background part in the manifest is content_scripts {"js":["background.js"]}).
Now I have written a code in popup.html that creates a connection (as I understand it, it starts when you click on the extension icon at the time the popup is displayed), the code is as follows:
chrome.windows.getCurrent(function(w){
chrome.tabs.getSelected(w.id,function(t){
port = chrome.tabs.connect(t.id);
port.onMessage.addListener(Answer);
});
});
chrome.extension.onConnect.addListener(function(port){
window.port = port;
port.onMessage.addListener(Question);
});
Answer the question
In order to leave comments, you need to log in
The popup is initialized every time it is opened and destroyed when it is closed. There is no way to get around this, except that when the port is closed, start adding messages to the queue and send them all when opened.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question