chrome.tabs.query({url: "*://xxxxxxxxxx.com/*"}, function reloadb() { window.document.querySelectorAll('.dropdown-item')[5].click(); // BUTTON NEWEST }); setInterval(reloadb, 5000); 

Why doesn't the code work? If you remove chrome.tabs.query({url: "*://xxxxxxxxxx.com/*"}, then the code will work, but I need this part of the code to be executed on a specific site. The extension reloads the page if it finds the right link sends the search form to another site. Therefore, the code for each site must be different. Just in case I will post the contents of the manifest file

 { "manifest_version": 2, "name": "BountySkins", "version": "0.1", "permissions": ["tabs"], "background": { "scripts": ["background.js"] }, "content_scripts": [ { "matches": [ "*://xxxxxxxxxx.com/*", "*://aaaaaaaaaa.net/*" ], "js": ["jquery-3.2.1.min.js", "content.js"] } ], "browser_action": { "default_icon": "icon.png" } } 

    1 answer 1

    The code contains common mistakes. If you just fix them stupidly, then the code will turn out like this

     function reloadb() { window.document.querySelectorAll('.dropdown-item')[5].click(); // BUTTON NEWEST } chrome.tabs.query({url: "*://xxxxxxxxxx.com/*"}, reloadb); setInterval(reloadb, 5000); 

    or if wrap in closure

     (function() { var reloadb = function() { window.document.querySelectorAll('.dropdown-item')[5].click(); // BUTTON NEWEST }; chrome.tabs.query({url: "*://xxxxxxxxxx.com/*"}, reloadb); setInterval(reloadb, 5000); })(); 

    But I doubt the need to call setInterval . And if I'm right, then everything turns into such a challenge.

     chrome.tabs.query({url: "*://xxxxxxxxxx.com/*"}, function() { window.document.querySelectorAll('.dropdown-item')[5].click(); // BUTTON NEWEST }); 
    • thank. I did as they said, but everything doesn’t work exactly Uncaught TypeError: Cannot read property 'query' of undefined on the line with the url error. I specify the link as well as in the manifesto - Udachnik
    • I understand, you can not use tabs in the content script, you need to use chrome.runtime - Udachnik