Comments (3)
I've been wondering if we should move to a more stateful approach — if we can at all.
Will take a look at this more this evening. At first glance, the proposal is reinventing ports: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/connect
from webext-messenger.
I mentioned that in the same comment. The problem with that is that either:
- the user has to manually connect and hold onto the
port
explicitly, bringing this complexity back into the app (point 3️⃣), or - if we don't change the API, it means we still need to attempt to connect every time a
target
is messaged but no openport
s are found (point 1️⃣)
runtime.connect
might be useful, but we still need to know how to adapt the messenger API/behavior around it. Just replacing runtime.sendMessage
doesn't solve these issues.
from webext-messenger.
I've been wondering if we should move to a more stateful approach — if we can at all.
The Messenger has been built around two core concepts:
- messaging opaqueness: call a function at an address (target), hide the transport protocol
- automatic retrying for missing and "unready" targets
The first part makes the communication stateless and independent, which means that the caller doesn't need to know much about the target and its life cycle (blessing and a curse).
The second part appears to be incredibly complicated and variable, which is why we've been tweaking it ever since.
Thinking out loud:
There are a few possible solutions to this, with varying degrees of complexity (none of this grants us bug armistice)
runtime.connect()
:- retry only the connection, connect once, reuse connection, know when the target is gone
- ok, what happens when it closes? We must reopen if it's a background page, but we never try again for
{target: "this", page: "sidebar.html"}
? Doesn't seem like a direct solution to all
webNavigation
API:- track and find frame IDs, then use a more exact
chrome.tabs.sendMessage(tab, frame)
message instead of named targets - this helps, but seems complex when it's time to retry on a new sidebar in the same tab for example
- track and find frame IDs, then use a more exact
- move target tracking to the user side:
- expose a stateful
obtainTarget({tab: 1})
API, then use it in the following communication, asopenSidebar(target)
andcloseSidebar(target)
. Once the target is closed, it's gone, and you need a new target - this forces the user to have to keep track of these targets internally and having to know when to attempt to obtain a new target
- expose a stateful
This feels like we're going to increase complexity exponentially and makes me long for a more straightforward approach instead. I'd love to be able to drop retrying and moving at least that part to the user side via internal API, like:
const sidebar = {target: "this", page: "sidebar.html"};
await messenger.expectTarget(sidebar); // Pings until it connects
await showPanel(sidebar); // Never retries
await updatePanel(sidebar); // Never retries
If the methods fail, they fail, the target is gone, we deal with it in the application as usual. I think this helps to give us control over when the trying happens "per target" instead of "per function call".
At any given time, we kind of know whether a target should exist or "will open soon". expectTarget
in this case would also replace a user land PING_SIDEBAR
method and other similar methods we have. It would probably help us emit more exact errors.
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.