Answer the question
In order to leave comments, you need to log in
How to clear a browserAction request?
When pressed again, the code triggers an alert 2 times, the next time it is pressed 3 times, and so on
, it needs to be only once, how to be? here is the code
chrome.browserAction.onClicked.addListener(function() {
chrome.tabs.executeScript({
file: 'sc.js'
});
chrome.tabs.query({url: "*://*.google.ru/*", currentWindow: true}, function(tabs) {
var port = chrome.tabs.connect(tabs[0].id);
port.postMessage("gshad");
})
});
chrome.runtime.onConnect.addListener(function(port) {
port.onMessage.addListener(function(msg) {
alert(msg)
});
});
Answer the question
In order to leave comments, you need to log in
The problem is not with browserAction, but with runtime.onConnect. You add a new handler every time - but the old handlers never go away!
I can advise you to embed your content script when loading the page - moreover, you know the urls where you need to embed. This will help avoid repeated calls to executeScript
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question