WebSerial browser window integration is potentially broken in multiple window case, and tightly coupled into browser-init
Categories
(Core :: DOM: Web Serial, defect, P2)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox155 | --- | fixed |
People
(Reporter: Gijs, Assigned: gstoll)
References
Details
Attachments
(1 file)
Unfortunately it would appear that https://phabricator.services.mozilla.com/D281259 did not get desktop core reviewers or other desktop folks involved for the changes in browser-init.js.
As it stands, every browser window will register an observer for "serial-device-state-changed" and the same observer will run N times for N windows, if/when the topic is notified, and every window will build up a weakmap pointing to browser objects across multiple windows. This is also adding globals to the main browser window, which we're desperately trying to avoid (we have a lint rule for browser.js globals and everything - we did not imagine people would start adding them to the other browser-n files which generally only have 1 global in them tobegin with).
We also reset the count if permission is removed (in only 1 map, in the window where the permission is removed - not all the other windows!), but nothing appears to ever read the map so it's unclear to me what the purpose of the map is.
If we do need it, this should be implemented using a singleton module, and probably use the ObserverForwarder to get instantiated so we do not pay JS load/run costs for it all the time when mostly, it will be unused code.
Greg, can you clarify the point of the map so we can make sure this is an actionable bug?
| Assignee | ||
Comment 1•3 months ago
|
||
Ack, sorry about this!
The point of this is to call updateBrowserSharing() when a serial port is in use (or when we were previously using serial ports but aren't any more), which in turn sets the "sharing" attribute on the tab, which we look at in CSS to show or hide the "port in use" icon (similar to if a camera is active, etc.)
The map gets read here so we can increment or decrement the current count for that browser.
Would this make sense to use an ObserverForwarder?
Comment 2•2 months ago
|
||
The severity field is not set for this bug.
:cmartin, could you have a look please?
For more information, please visit BugBot documentation.
Updated•2 months ago
|
| Assignee | ||
Comment 3•2 months ago
|
||
This avoids having one of these per window.
Updated•2 months ago
|
Updated•2 months ago
|
Comment 5•1 month ago
|
||
| bugherder | ||
Updated•1 month ago
|
Description
•