#Page/Extension Communication
1 messages · Page 1 of 1 (latest)
Hey!
Take a look at https://developer.chrome.com/docs/extensions/develop/concepts/messaging for communicating between your extension and your web page
How to pass messages between extensions and content scripts.
An explanation of content scripts and how to use them in your Chrome Extension.
Explains content scripts
https://developer.chrome.com/docs/extensions/develop/concepts/service-workers for service workers
Extension service workers are an extension's central event handler. That makes them different from web service workers.
Hey thanks. Yeah I read the doc; but it's like i'm missing something... Maybe read one more time ? 😉
from my page script, I need to call a content script, which in turn can call an extension, which in turn can call cool APIs.
I can't figure out how to load a content script if it is even possible, because the documentation is about extensions, not page scripts or app or PWA.
Oh, and my app is a digital signage app, so there is no user interaction (if that matters in any way).
The Content scripts docs page describes a number of ways to add content scripts to a page, including being declared statically, dynamically, or programatically injected. (https://developer.chrome.com/docs/extensions/develop/concepts/content-scripts#functionality)
An explanation of content scripts and how to use them in your Chrome Extension.
And you can communicate between a page script (the site's JavaScript) and your content script by following the instructions under Send Messages from a web page in the Message passing docs (https://developer.chrome.com/docs/extensions/develop/concepts/messaging#external-webpage)
How to pass messages between extensions and content scripts.
Send a message from your Kiosk app to your extension requesting the serial number, run the required APIs to get the serial number, and respond to the message with it
Thanks for the follow-up !
I think I got the doc right, but that there's a lot of pre-conditions for this to work.
As of now :
- It doesn't look like I can statically load a very simple content script with "web_accessible_resources".
- I still can't call chrome.runtime.sendMessage() even with "externally_connectable".
I am obviously missing something somewhere 😉
Sample App at https://pwa.deepidoo.dev
Just trying to call power.keepAwake()
You won't be able to call extension APIs from your web page, you can only do it from your extension.
You have your extension ID and your extension is running?
Yes, but I still have no clue on how to call it from my PWA. nothing in chrome.runtime...
Got it. I missed the "externally_connectable" in the extension's manifest and that magically makes chrome.runtime.sendMessage() available in the PWA.
Now, I am struggling to force-install my self-hosted extension in a ChromeBox. No error but no extension.
Any way to get some logs about that ?