Add support for `web_accessible_resources` contexts
martonlederer opened this issue · 1 comments
Usecase
You have an extension with html files added to web_accessible_resources
in the manifest. These pages should be allowed to communicate with the background script and other pages, similarly to how for e.g. the popup
page can communicate with the background script.
The problem
webext-bridge
currently does not treat these pages from web_accessible_resources
as different contexts, rather it detects them as background
contexts. This prevents them to communicate with the background script, even through there is no security risk here, as the browser.runtime.sendMessage
/browser.runtime.onMessage
APIs are already exposed to them.
Potential solution
Create a new type of context (e.g.: web_accessible
) that behaves similarly to how the content-script
contexts work. There could be multiple pages added to web_accessible_resources
, so this would allow you to send messages to specific pages as well, using their tabId
.
Example
Send a message to a page with "web_accessible
" context and the tabId 3412
:
const returnData = await sendMessage('bar', { /* ... */ }, "web_accessible@3412");