I'm trying to build a browser extension and I need some help. I'm looking for a way to make my service worker utilize functions from a website. When I try to do something like `document.querySelector("foo").bar.doFunction()`, it works in my Chrome browser at the top level, but I can't seem to get it to work with my service worker. Any advice?
3 Answers
You might want to explore extension message passing. Setting up a message event listener in your service worker and sending messages from your content script could help with the communication you're looking for.
It sounds like you're at a tricky stage. I recommend checking out some tutorials to get a solid grasp on the basics. Chrome and Mozilla have some great resources that could help you along the way.
I've got a simple example of browser extension communication that might help you out. Check it out here: https://github.com/molvqingtai/comctx/tree/master/examples/browser-extension. It could clarify how to structure your code!

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically