Subscribing to WebDriver BiDi network events blocks the parent process main thread while pages load
Categories
(Remote Protocol :: Agent, defect, P3)
Tracking
(firefox160 fixed)
| Tracking | Status | |
|---|---|---|
| firefox160 | --- | fixed |
People
(Reporter: julienw, Assigned: jdescottes)
References
(Blocks 1 open bug)
Details
(Keywords: perf, Whiteboard: [webdriver:m22][webdriver:relnote])
Attachments
(2 external files)
When a WebDriver BiDi client subscribes to network events (such as using the devtools mcp with claude), the DevTools NetworkObserver computes security info for every HTTPS response on the parent main thread, in onStartRequest (https://searchfox.org/firefox-main/rev/0d4ba5e140b8d1f53c431beebf89cb6bed20b3d6/devtools/shared/network-observer/NetworkResponseListener.sys.mjs#430-450). This decodes the server certificate with pkijs (https://searchfox.org/firefox-main/rev/0d4ba5e140b8d1f53c431beebf89cb6bed20b3d6/devtools/shared/network-observer/NetworkHelper.sys.mjs#768-775). The first time, it also synchronously imports certDecoder.mjs and pkijs.js (https://searchfox.org/firefox-main/rev/0d4ba5e140b8d1f53c431beebf89cb6bed20b3d6/devtools/shared/network-observer/NetworkHelper.sys.mjs#78).
The Remote Agent throws the result away: NetworkEventRecord.addSecurityInfo is empty and documented as "Not used for RemoteAgent" (https://searchfox.org/firefox-main/rev/0d4ba5e140b8d1f53c431beebf89cb6bed20b3d6/remote/shared/listeners/NetworkEventRecord.sys.mjs#201).
Profile of a cold load of lemonde.fr (Nightly 158, Linux), driven by the firefox-devtools MCP server: https://share.firefox.dev/4hIf2Zb
- 181 of 799 active samples on the parent main thread are in
#getSecurityInfo. - The document's
OnStartRequesttakes 131 ms, 77 ms of it thecertDecoder.mjsimport, which delays the HTML reaching the content process by about that much.
Possible fix: NetworkObserver already takes opt-outs such as decodeResponseBodies (https://searchfox.org/firefox-main/rev/0d4ba5e140b8d1f53c431beebf89cb6bed20b3d6/devtools/shared/network-observer/NetworkObserver.sys.mjs#228). A similar option to skip security info, passed by the Remote Agent's NetworkListener, would remove this cost for every BiDi client.
Comment 1•1 month ago
|
||
The severity field is not set for this bug.
:whimboo, could you have a look please?
For more information, please visit BugBot documentation.
Comment 2•1 month ago
|
||
Retrieving security details and adding those to the network response event is something Playwright want to have (see the second list in this GitHub comment). So we should potentially add that instead.
| Assignee | ||
Updated•1 month ago
|
| Reporter | ||
Comment 3•1 month ago
|
||
I wonder how we can both make Playwright and the profiler use case happy...
| Assignee | ||
Comment 4•1 month ago
|
||
I think we could add a flag in the network observer and a preference, but one comment about:
- 181 of 799 active samples on the parent main thread are in #getSecurityInfo.
- The document's OnStartRequest takes 131 ms, 77 ms of it the certDecoder.mjs import, which delays the HTML reaching the content process by about that much.
I imagine those 2 observations are mostly relevant for the first request? Half of the samples and time are related to importing the module, which should only happen once. And onStartRequest does not await on #getSecurityInfo, so in theory it should not block sending the request completely (although if it keeps the main thread busy I imagine it can still delay things).
What we should check is how much needs to happen in onStartRequest. I suspect that at least parsing the certificate could be done lazily when the consumer needs to read the information?
We could also load the certDecoder module upfront to avoid the additional cost on the first request (although I think that would not be a good fit for DevTools, which want to make toolbox startup as fast as possible).
We could also workaround this on the MCP side. At the moment we subscribe to network events eagerly, even if you don't need the network tools, but I don't think this is a good option in the long run.
| Assignee | ||
Comment 5•1 month ago
|
||
(In reply to Henrik Skupin [:whimboo][⌚️UTC+2] from comment #2)
Retrieving security details and adding those to the network response event is something Playwright want to have (see the second list in this GitHub comment). So we should potentially add that instead.
On that topic, I checked the current API docs from Playwright: https://playwright.dev/docs/api/class-apiresponse#api-response-security-details, the information they require needs to parse the certificate AFAICT.
| Assignee | ||
Comment 6•1 month ago
•
|
||
(In reply to Julian Descottes [:jdescottes] from comment #5)
(In reply to Henrik Skupin [:whimboo][⌚️UTC+2] from comment #2)
Retrieving security details and adding those to the network response event is something Playwright want to have (see the second list in this GitHub comment). So we should potentially add that instead.
On that topic, I checked the current API docs from Playwright: https://playwright.dev/docs/api/class-apiresponse#api-response-security-details, the information they require needs to parse the certificate AFAICT.
One clarification on that point. In theory at the moment we could skip decoding the certificate, because the necessary fields still exist on nsIX509Cert, but that goes against the goal of Bug 1664048. The DevTools codebase was migrated out of reading the fields directly a few years ago in Bug 1688703. So doing that would add back unwanted consumers for those fields.
I think our next steps here should be:
1/ Add a flag to opt out from the DevTools certificate parsing.
2/ Security details BiDi spec work. Playwright securityDetails() API is async, in theory we should be able to specify this as a new command instead of including it in every network event by default. This is compatible with the Playwright API, but their current implementations don't really handle that (at most they wait on existing promises). So we need to check whether this is fine for them.
3.a/ If the conclusion of the spec work is a command we implement it using the same helpers as devtools.
3.b/ If not, we can try to rework the certificate parsing to become fully lazy / ondemand. DevTools would request it late, when the UI needs the information. BiDi would still have to do it for every request, but it can be delayed until responseCompleted.
| Assignee | ||
Comment 7•1 month ago
|
||
Adds a flag in the DevTools NetworkObserver to optout from parsing security info.
We have an upcoming requirement from Playwright to add security details, but it should actually
be accessible on nsIX509Cert directly, without having to parse the certificate in details.
Updated•1 month ago
|
| Assignee | ||
Comment 8•1 month ago
|
||
Comment 10•1 month ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/ab942c8b88b3
https://hg.mozilla.org/mozilla-central/rev/b53285461a5f
| Assignee | ||
Updated•20 days ago
|
Description
•