Skip to content Skip to sidebar Skip to footer

Why Is My Javascript Chrome Extension Code Not Working? (loop Check For Button)

I am trying to make a chrome extension that constantly checks for the button with the ID 'product-addtocart-button', and as soon as it is found it will click. I have came together

Solution 1:

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 that and see how it goes.

Solution 2:

Use content script file instead of background.js if you want to trigger the click for a specific page.

"content_scripts":[{"matches":["http://www.google.com/*"],"css":["mystyles.css"],"js":["jquery.js","myscript.js"]}],

download JQuery into your local folder if you want to use JQuery .

if($('#product-addtocart-button').length>0)
$('#product-addtocart-button').click()

Post a Comment for "Why Is My Javascript Chrome Extension Code Not Working? (loop Check For Button)"