Comments (6)
This is what happens exactly and why duplicate injection is an issue:
- Two copies of the messenger a run in sequence, each with its own registry
- They are not deduplicated because webpack does not deduplicate across entry points
- They both add their own
onMessage
listener, which looks into its own registry for matchingMESSAGE_TYPE
- The second copy is the one registering our expected ~40 methods
Now, when the content scripts receives a message, who handles it?
- The first
onMessage
listener finds an empty registry and it handles the message, responding with theno methods registered here
error - The second
onMessage
listener never hears of the message, even if it's ready to call its method
from webext-messenger.
FYI -- pre-rendering would explain the weird frame ids we were experiencing (that were causing duplicate injections):
w3c/webextensions#396 (comment)
from webext-messenger.
This is what happens exactly
This summary definitely matches what I was seeing 💯
from webext-messenger.
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
from webext-messenger.
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 FRAME 0 === TOP
assumption for active documents.
The messenger does not use webNavigation
API so it should generally not see pre-rendered pages.
However the extension does use the API and its events, we should probably review its usage:
FWIW, I think this method is still correct though for detecting in contentScript if it's loaded in an iframe?:
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:
from webext-messenger.
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;
}
from webext-messenger.
Related Issues (20)
- Remove branch protection from repo HOT 1
- Drop `webextensions-polyfill` to avoid unnecessary abstraction
- Toggle WEBEXT_LOGGING at runtime
- Dispatch retries event and retry-exhaustion event
- Do not retry discarded tabs, return specific error
- Use `browser.runtime.getFrameId()` HOT 1
- Update Parcel
- Track timing HOT 2
- Immediately handle context invalidation, disabling further messaging
- Accept `Promise<Target>`
- Support `allFrames` as target
- Ensure sequence numbers are never reused HOT 2
- Error: Tabs cannot be edited right now (user may be dragging a tab).
- `retry: false` not respected when forwarding
- Add `extractTargetFromSender`
- Unwanted forwarding when targeting `allFrames` HOT 2
- Fail when trace.length > 2 HOT 2
- Meta: update parcel to 2.12+
- Preserve seq number when forwarding
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webext-messenger.