-
-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
disfunction to send message from an iframe page to background and others #47
Comments
I found in such context that the portId has the format
if (context === 'background') {
browser.runtime.onConnect.addListener((incomingPort) => {
// when coming from devtools, it's should pre-fabricated with inspected tab as linked tab id
let portId = incomingPort.name || `content-script@${incomingPort.sender.tab.id}`
const portFrame = incomingPort.sender.frameId
if (portFrame)
portId = `${portId}.${portFrame}`
... for example: the result of parseEndpoint("options.123") is so I temporarily modified two places of code: line: 108 let portId = incomingPort.name || `content-script@${incomingPort.sender.tab.id}`
const portFrame = incomingPort.sender.frameId change to const portTabId = incomingPort.sender?.tab?.id
if (portId === 'options' && portTabId)
portId = `${portId}@${portTabId}`
const portFrame = incomingPort.sender.frameId line 212: let resolvedDestination = ['popup', 'options'].includes(destName)
? destName
: (`${(destName === 'window' ? 'content-script' : destName)}@${(destTabId || srcTabId)}`) change to let resolvedDestination = ['popup', 'options'].includes(destName)
? `${destName}@${destTabId}`
: (`${(destName === 'window' ? 'content-script' : destName)}@${(destTabId || srcTabId)}`) now, send message from an iframe to background can effects! |
This is a good find. You should create a pull request for this change. |
wrap one of the extension pages as an iframe is an new extension design pattern, which is recommended by quasar. but there are some communication problems when I use webext-bridge to this pattern.
for example, I use the
options/index.html
as the iframe page, (https://github.com/antfu/vitesse-webext as the base template)so, in
contentScripts/index.ts
then, in options/index.html, I add an button of which the handler function is
test
to start the sendmessage testin
background.ts
send I open an new page and clicked the test button in the iframe some times, the console show as the follow:
console of background
(nothing!)
it proved that it's failed to send messages to background.
that I open the
options/index.html
directly through the menu on popup icon. and replay the test again.this time, it's successful.
console of
options/index.html
console of
background
@antfu @zikaari How can I do to enable the communication from an iframe to background with webext-bridge?
The text was updated successfully, but these errors were encountered: