If you want it to run automatically, without any user action (like an extension button click), you can use
content scripts. This is a key (
content_scripts) you define in the manifest with a list of objects of a URL pattern to match and the files you want to run.
If you want it to run on demand (via the extension button click or an extension popup and a click within it), you need to listen to the
chrome.action.onClicked event and use
chrome.scripting.executeScript to run the script in its handler (
documentation).
- If you only need the extension button click, you need to add a small service worker with code to listen to the event and run the script in its handler as in the above.
- If you need it within an extension popup, you need to declare a popup in the manifest, listen to the relevant event in your popup as usual (it is a normal webpage) and when handling that event, run the script.