background script:
let msg = 'ty for help';
chrome.browserAction.onClicked.addListener(function (event) {
console.log('clicked');
chrome.tabs.executeScript(null, {
file: 'js/content.js', /* my content script */ }, () => {
connect(msg) //this is where I call my function to establish a connection
});
});
});
function connect(msg) {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const port = chrome.tabs.connect(tabs[0].id);
port.postMessage(msg);
});
}
content script:
chrome.runtime.onConnect.addListener(function(port) {
port.onMessage.addListener(function(show_floater) {
console.log('why do I get printed more than once per click?????');
});
});
The behaviour I'd like is for the code of my content script to be executed ONCE every time the user clicks on the extension icon of the browser. As of now for every click it is called multiple times. Here, under port lifetime it says that onConnect may be called for all the frames. I tried to set all_frames to false in the manifest but nothing changes... send help D: