I am working on my first extension project and could use some assistance.

58 views
Skip to first unread message

Thurston Daly

unread,
Mar 6, 2023, 9:16:54 PM3/6/23
to Chromium Extensions
I have created a browser extension with the objective of automatically selecting a radio button on a specific website. The website features a schedule with a corresponding radio button for each scheduled item. I have already written the necessary JavaScript code that scans the website's HTML, reads the schedule, and selects the appropriate radio button. While the code works when entered into the console, I want it to run automatically when the website is open on an active or background tab. I attempted to use the scripting and activeTab permissions to accomplish this, but the code still won't run. I'm unsure if it's even possible for an extension to perform this task, so I would appreciate any suggestions or advice. Thank you.

PhistucK

unread,
Mar 7, 2023, 4:13:13 AM3/7/23
to Thurston Daly, Chromium Extensions
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.


PhistucK


On Tue, Mar 7, 2023 at 2:17 AM Thurston Daly <dal...@gmail.com> wrote:
I have created a browser extension with the objective of automatically selecting a radio button on a specific website. The website features a schedule with a corresponding radio button for each scheduled item. I have already written the necessary JavaScript code that scans the website's HTML, reads the schedule, and selects the appropriate radio button. While the code works when entered into the console, I want it to run automatically when the website is open on an active or background tab. I attempted to use the scripting and activeTab permissions to accomplish this, but the code still won't run. I'm unsure if it's even possible for an extension to perform this task, so I would appreciate any suggestions or advice. Thank you.

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/53ddc7ab-aa45-440a-95c0-9119f35ff577n%40chromium.org.
Reply all
Reply to author
Forward
0 new messages