Bug 255402 - Web Inspector doesn't show nested workers
Summary: Web Inspector doesn't show nested workers
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Devin Rousso
URL: https://safari-subworker.glitch.me/
Keywords: BrowserCompat, InRadar
: 255637 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-04-13 09:33 PDT by Thomas Steiner
Modified: 2024-06-06 22:47 PDT (History)
9 users (show)

See Also:


Attachments
Safari Console (512.54 KB, image/png)
2023-04-13 09:33 PDT, Thomas Steiner
no flags Details
Safari Network (601.98 KB, image/png)
2023-04-13 09:33 PDT, Thomas Steiner
no flags Details
Safari Sources (652.18 KB, image/png)
2023-04-13 09:34 PDT, Thomas Steiner
no flags Details
Chrome (321.44 KB, image/png)
2023-04-13 09:34 PDT, Thomas Steiner
no flags Details
Firefox (689.33 KB, image/png)
2023-04-13 09:34 PDT, Thomas Steiner
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Steiner 2023-04-13 09:33:04 PDT
Created attachment 465890 [details]
Safari Console

A Web Worker can spawn other Web Workers; these are sometimes referred to as subworkers or sub-workers. Safari does not seem to request the subworker file and only spawns a Worker from the main thread.

Note the screenshots:

chrome.png: The expected behavior in Chrome.
firefox.png: The expected behavior in Firefox.
safari-console.png: Safari only logs the message from worker.js.
safari-network.png: Safari does not seem to make the request for subworker.js.
safari-sources.png: Safari does not show subworker.js in its sources.

Minimal repro: https://safari-subworker.glitch.me/
Comment 1 Thomas Steiner 2023-04-13 09:33:41 PDT
Created attachment 465891 [details]
Safari Network
Comment 2 Thomas Steiner 2023-04-13 09:34:02 PDT
Created attachment 465892 [details]
Safari Sources
Comment 3 Thomas Steiner 2023-04-13 09:34:19 PDT
Created attachment 465893 [details]
Chrome
Comment 4 Thomas Steiner 2023-04-13 09:34:33 PDT
Created attachment 465894 [details]
Firefox
Comment 5 Thomas Steiner 2023-04-13 09:59:47 PDT
This does _not_ work in:

- Safari Tech Preview Release 167 (Safari 16.4, WebKit 18616.1.8.2)
- Safari Version 16.5 (18615.2.5.11.2)

(I'm on Ventura 13.4 Beta (22F5037d))
Comment 6 Alexey Proskuryakov 2023-04-13 14:59:58 PDT
Nested workers were implemented in bug 22723, quite surprising that this isn't working.
Comment 7 Karl Dubost 2023-04-13 16:08:18 PDT
And this is passing. 
https://wpt.fyi/results/workers/semantics/multiple-workers/003.html?label=experimental&label=master&aligned


And the example given in the spec.
https://html.spec.whatwg.org/multipage/workers.html#delegation
is working
https://html.spec.whatwg.org/demos/workers/multicore/page.html

Maybe it's about something else. Is it about the console.log()?
Comment 8 Karl Dubost 2023-04-13 16:15:09 PDT
I even wonder if it's in fact just a Web Inspector issue.
a bit like Bug 252685
Comment 9 Dasa Paddock 2023-04-13 16:20:33 PDT
That sounds right. I see that https://safari-subworker.glitch.me/subworker.js does get loaded when I test https://safari-subworker.glitch.me and have Charles Proxy running.
Comment 10 Karl Dubost 2023-04-13 16:33:33 PDT
I renamed the bug.
Comment 11 Sam Sneddon [:gsnedders] 2023-04-14 04:23:45 PDT
On Safari 16.4, macOS Ventura 13.3.1 (22E261), MacBook Pro 14" 2023 (Mac14,9), I am seeing the "from subworker" console messages, though I can't see anything in the Sources or Network tabs.

Given I can see them on relatively fast hardware, this makes me wonder if there's some race happening somewhere?
Comment 12 Thomas Steiner 2023-04-14 04:52:04 PDT
I have added a bunch of postMessage() calls to the demo at https://safari-subworker.glitch.me/, so we can see communication happening in all directions. I can indeed confirm that the worker.js postMessage() call arrives in subworker.js, since its response is logged in worker.js.

## Here're the logs from Chrome:

Hello from main thread
worker.js:1 Hello from worker.js
worker.js:4 Message received in worker.js: From main thread to worker.js
script.js:6 Message received in main thread: From worker.js to main thread after message from main thread
subworker.js:1 Hello from subworker.js
subworker.js:4 Message received in subworker.js: From worker.js to subworker.js
worker.js:11 Message received in worker.js: From subworker to worker.js
script.js:6 Message received in main thread: From worker.js to main thread after message from subworker.js


## Here're the logs from Firefox:

Hello from main thread script.js:1:9
Hello from worker.js worker.js:1:9
Message received in worker.js: From main thread to worker.js worker.js:4:11
Message received in main thread: From worker.js to main thread after message from main thread script.js:6:11
Hello from subworker.js subworker.js:1:9
Message received in subworker.js: From worker.js to subworker.js subworker.js:4:11
Message received in worker.js: From subworker to worker.js worker.js:11:11
Message received in main thread: From worker.js to main thread after message from subworker.js script.js:6:11

​
## Here're the logs from Safari (Safari Tech Preview and Stable agree): 

[Log] Hello from main thread (script.js, line 1)
[Log] Hello from worker.js (worker.js, line 1)
[Log] Message received in worker.js: – "From main thread to worker.js" (worker.js, line 4)
[Log] Message received in main thread: – "From worker.js to main thread after message from main thread" (script.js, line 6)
[Log] Message received in worker.js: – "From subworker to worker.js" (worker.js, line 11)
[Log] Message received in main thread: – "From worker.js to main thread after message from subworker.js" (script.js, line 6)


This means it's indeed a complete Web Inspector blindness to anything happening in subworker.js. 

Also, it doesn't yet explain why SQLite Wasm backed by the OPFS (https://sqlite-wasm-opfs.glitch.me/) isn't working on Safari yet, but that's a different story then (maybe). I'll keep investigating. The subworkers theory was a good lead, though…
Comment 13 Thomas Steiner 2023-04-14 09:02:50 PDT
Found the root cause of the SQLite Wasm problem: `navigator.storage.getDirectory()` fails in subworker with an `InvalidStateError`: https://bugs.webkit.org/show_bug.cgi?id=255458.
Comment 14 Radar WebKit Bug Importer 2023-04-20 09:34:19 PDT
<rdar://problem/108322385>
Comment 15 Devin Rousso 2023-05-08 17:40:50 PDT
Pull request: https://github.com/WebKit/WebKit/pull/13614
Comment 16 Alexey Proskuryakov 2023-05-24 09:29:45 PDT
*** Bug 255637 has been marked as a duplicate of this bug. ***
Comment 17 Alexey Proskuryakov 2024-04-09 11:49:47 PDT
*** Bug 272382 has been marked as a duplicate of this bug. ***
Comment 18 EWS 2024-06-06 22:47:53 PDT
Committed 279793@main (b5d3f9b6724b): <https://commits.webkit.org/279793@main>

Reviewed commits have been landed. Closing PR #13614 and removing active labels.