-
Notifications
You must be signed in to change notification settings - Fork 2
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
Handle repeated injection gracefully #88
Comments
FYI -- pre-rendering would explain the weird frame ids we were experiencing (that were causing duplicate injections): |
This is what happens exactly and why duplicate injection is an issue:
Now, when the content scripts receives a message, who handles it?
|
This summary definitely matches what I was seeing 💯 |
Additional commentary from Chrome team on relationship between tabs and frames: https://developer.chrome.com/blog/extension-instantnav/#outermost-frame FWIW, I think this method is still correct though for detecting in contentScript if it's loaded in an iframe?: https://github.com/pixiebrix/pixiebrix-extension/blob/80b362f6a3f869a81b63eb64b0a79919a642e1fc/src/utils/iframeUtils.ts#L22-L22 |
Re: Frames I'm going to guess that those changes do not affect our usage for the most part, at least as far as the messenger is concerned, because we message alive and active documents. I think (I hope) that they didn't change the The messenger does not use However the extension does use the API and its events, we should probably review its usage:
That's always valid, it's the only way for a content script to know that anyway, it does not have access to the frame ID in any other way, at least until: |
Quickest solution to avoid further frustration: if (window[MESSENGER_SYMBOL]) {
console.error('webext-messenger was loaded twice, do XYZ, https://link')
} else {
window[MESSENGER_SYMBOL] = true;
} |
Due to this error, mistakenly running the messenger twice (e.g. via
executeScript
) will now cause the second handler to respond with an error: The "registered methods" array is empty for every execution because it's not shared.Possible solutions
registerMethods
, which would have to throw an error)window[MESSENGER_SYMBOLS] ??= []
cc @twschiller
The text was updated successfully, but these errors were encountered: