Giter Site home page Giter Site logo

Comments (3)

twschiller avatar twschiller commented on August 22, 2024 1

There's a few different scenarios:

  1. A singleton extension "component", e.g., the PixieBrix sidebar of which there will ever be at most 1 on the page
  2. A persistent frame that the extension added, e.g., an inline panel that uses a frame for showing its content to isolate styles/hotkeys from the main page. In this case, there may be more than 1 frame, but they could potentially be uniquely identified by the extension id that placed the frame
  3. Frames from 3rd party sites. E.g., a common case is a iframe embedded in a SaaS app via the app's marketplace. (I.e., the SaaS app is using frames to protect against malicious apps in their marketplace)

Therefore I think supporting a couple patterns could be useful:

  • Allow a frame to register a unique name that it can be referenced by on the tab. This also enables scenario 2 because the contentScript would know the name of the frame ahead of time (at least in our case, it could be derived from the extension id)
  • Support matching by frame URL, with the caller selecting whether multiple matches are an error or result in an array of responses being response

Related:

from webext-messenger.

fregante avatar fregante commented on August 22, 2024

This could happen in the user’s code, but it would mean having to implement mapping, waiting, registration events, etc… outside webext-messenger

I'm going to implement named targets. More in:

from webext-messenger.

fregante avatar fregante commented on August 22, 2024

Currently the messenger lets us target chrome-extension pages by URL since chrome.runtime.sendMessage will send a message to every such page:

doSomething({ page: "/iframe.html" }, ...args);

it can also target such page in a specific tab:

doSomething({ page: "/iframe.html", tabId: 123 }, ...args);

chrome.tabs.sendMessage can do something similar IIRC, but only as long as you know the tab ID:

// I think
browser.tabs.sendMessage(tabId, message, {
	allFrames: true
})

The messenger does not support this yet, but maybe we can implement it:

doSomething({ page: "https://full.page.url/iframe.html", tabId: 123 }, ...args);

With two requirements:

  • it must receive a tab ID
  • it must receive a full https URL so that the messenger knows whether to use chrome.runtime or chrome.tabs to send the message

Since content scripts cannot use the chrome.tabs API, the messenger would have to forward them via the background page as well.

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.