I know that we can access chrome.hid.getDevices() in chrome app. but I have also heard that chrome.hid.getDevices() can only be used in chrome app.
But can we somehow access chrome.hid.getDevices() in chrome extensions. Because I need to inject scripts using Content-script so that I can use my extension functions from Web page and according to my knowledge Content-script can only be used in Chrome Extension.
Is there any example to communicate with Chrome app with web pages?
What about maintaining both extension and apps, since apps have access to USB devices while extensions can inject scripts to web pages, you could use Message Passing, such as chrome.runtime.sendMessage
and chrome.runtime.connect
to establish connection between extension and apps.
The first parameter for above two methods is extensionId
, which could be set external extension/app id.
If you intend to directly call your functions from website code, you don't need an extension/content script as a proxy.
A specific domain can be whitelisted in "externally_connectable"
manifest key to be able to initiate messaging with your app.
After that:
chrome.runtime.sendMessage()
or .connect()
with app's ID.chrome.runtime.onMessageExternal
or onConnnectExternal
event.If listeners to those events are registered in the event page, it will be woken up to handle them even if the app is not launched.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With