I can not figure out how to make the extension in the background made small changes on the current and all subsequent tabs, when they are opened.

For a one-time change of the content of the page it is not difficult, but how to make the extension work in the background is not clear.

If anyone can help with specific advice or a link to suitable solutions / functions / libraries (preferably with Russian documentation) I would be very grateful.

Manifesto:

{ "name": "A browser action with a popup that changes the page color", "description": "Change the current page color", "version": "1.0", "permissions": [ "tabs", "http://*/*", "https://*/*" ], "background": { "scripts": ["eventPage.js"], "background_page" : "background.html", "persistent": false }, "browser_action": { "default_title": "Set this page's color.", "default_icon": "icon.png", "default_popup": "popup.html" }, "manifest_version": 2 } 

Js:

 function click(e) { chrome.tabs.executeScript(null, {code:"document.body.style.backgroundColor='" + e.target.id + "';"}); chrome.tabs.executeScript(null, {code:"var mEl=document.querySelectorAll('*') ; for (var i = 0; i < mEl.length; i++ ){mEl[i].style.backgroundColor='" + e.target.id + "';\ mEl[i].style.color = 'green';\ \};"}); window.close(); } document.addEventListener('DOMContentLoaded', function () { var divs = document.querySelectorAll('div'); for (var i = 0; i < divs.length; i++) { divs[i].addEventListener('click', click); } }); 

    1 answer 1

    Do you need the extension to be launched every time you open a new tab?

    If so, then you can in the manifest ( manifest.json ) specify the js file that will be executed for each newly opened browser tab.

    Documentation is here . A good description of how to create an extension on habrahabr .

    Example:

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