How to change the content on the active tab in Chrome using the extension? Permission to work with tabs received.

    1 answer 1

    You can do this:

    https://developer.chrome.com/extensions/activeTab

    A brief retelling.

    You register activeTab in manifest.json in the permission section.

    Further in the background section we prescribe a script that should be executed.

    And basically everything.

    chrome.browserAction.onClicked.addListener(function(tab) { console.log('Turning ' + tab.url + ' red!'); chrome.tabs.executeScript({ code: 'document.body.style.backgroundColor="red"' }); }); 

    Ie by clicking on the extension icon (browser action), the code will be executed (in the current tab), which was transferred to executeScript as a parameter.

    Here the finished line of code is transferred to executeScript , but you can simply pass the name of the file, which will then be embedded in the page. For remaining information on the function, refer to the documentation.

    Everything else depends on your idea of ​​when / what should work.

    It is possible to try to play with chrome.tabs.onActivated or with some suggested functionality.

    • and how to execute the code not at the click, but immediately? possible on a specific site - ikerya