Comments (3)
There's a few different scenarios:
- A singleton extension "component", e.g., the PixieBrix sidebar of which there will ever be at most 1 on the page
- 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
- 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:
- pixiebrix/pixiebrix-extension#1603. This issue was created with scenario #3 in mind
from webext-messenger.
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.
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 usechrome.runtime
orchrome.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)
- Remove branch protection from repo HOT 1
- Handle repeated injection gracefully HOT 6
- 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.