Giter Site home page Giter Site logo

Comments (6)

fregante avatar fregante commented on August 22, 2024 1

This is what happens exactly and why duplicate injection is an issue:

  1. 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
  2. They both add their own onMessage listener, which looks into its own registry for matching MESSAGE_TYPE
  3. The second copy is the one registering our expected ~40 methods

Now, when the content scripts receives a message, who handles it?

  1. The first onMessage listener finds an empty registry and it handles the message, responding with the no methods registered here error
  2. The second onMessage listener never hears of the message, even if it's ready to call its method

from webext-messenger.

twschiller avatar twschiller commented on August 22, 2024

FYI -- pre-rendering would explain the weird frame ids we were experiencing (that were causing duplicate injections):
w3c/webextensions#396 (comment)

from webext-messenger.

BLoe avatar BLoe commented on August 22, 2024

This is what happens exactly

This summary definitely matches what I was seeing 💯

from webext-messenger.

twschiller avatar twschiller commented on August 22, 2024

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.

fregante avatar fregante commented on August 22, 2024

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.

fregante avatar fregante commented on August 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.