Chrome Extension Loop Check For Button Errors
I am trying to create a chrome extension that once I click the chrome extension, the script will start and will loop check every 1 millisecond for a button with the id 'product-add
Solution 1:
Answering the question for the 3rd time (please stop posting new questions for the same problem):
According to specifications, you have to invoke executeScript like:
chrome.tabs.executeScript(tab.id,{code:"yourCodePackedIntoOneString"});
or
chrome.tabs.executeScript(tab.id,{file:"yourCodeFile.js"});
but you are calling:
chrome.tabs.executeScript(tab.id,{function()etc...});
.
Try this:
Have one file called myWaitingLoop.js:
functionwaitForElementToDisplay(){
var button = document.querySelector("#product-addtocart-button");
if (button){
button.click();
} else {
setTimeout(waitForElementToDisplay,100);
}
}
waitForElementToDisplay();
and then, in your background.js script:
chrome.browserAction.onClicked.addListener(function(tab){
chrome.tabs.executeScript(tab.id,{file:"myWaitingLoop.js"});
});
Post a Comment for "Chrome Extension Loop Check For Button Errors"