Bug 255458 - `navigator.storage.getDirectory()` fails in nested workers with an `InvalidStateError`
Summary: `navigator.storage.getDirectory()` fails in nested workers with an `InvalidSt...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Sihui Liu
URL:
Keywords: BrowserCompat, InRadar
Depends on:
Blocks: 22723
  Show dependency treegraph
 
Reported: 2023-04-14 08:57 PDT by Thomas Steiner
Modified: 2023-04-18 08:52 PDT (History)
4 users (show)

See Also:


Attachments
Safari (203.39 KB, image/png)
2023-04-14 08:57 PDT, Thomas Steiner
no flags Details
Chrome (117.54 KB, image/png)
2023-04-14 08:59 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-14 08:57:07 PDT
Created attachment 465914 [details]
Safari

1. Go to https://opfs-in-subworker.glitch.me/ in Chrome or Firefox.
2. Open the Console.
3. Note how calls to `navigator.storage.getDirectory()` succeed in the main thread, a worker, and a subworker.
4. Go to https://opfs-in-subworker.glitch.me/ in Safari.
5. Open the Console.
6. Note how calls to `navigator.storage.getDirectory()` succeed in the main thread, a worker, but fail in a subworker with an `InvalidStateError`.

## Console dump from Safari:

[Log] Succeeded in main thread (script.js, line 4)
FileSystemDirectoryHandle kind: "directory" name: "" FileSystemDirectoryHandle Prototype

[Log] Succeeded in worker.js (worker.js, line 4)
FileSystemDirectoryHandle kind: "directory" name: "" FileSystemDirectoryHandle Prototype

[Log] Message from subworker.js: (worker.js, line 12)
Object error: InvalidStateError: The object is in an invalid state. code: 11 message: "The object is in an invalid state." name: "InvalidStateError" Error Prototype message: "Failed in subworker.js InvalidStateError: The object is in an invalid state."
Object Prototype

I believe the problem lies somewhere here: https://github.com/WebKit/WebKit/blob/9da2b02e31a2ba79c73354b04dc59aea0d04bb88/Source/WebCore/Modules/storage/StorageManager.cpp#L138-L141.
Comment 1 Thomas Steiner 2023-04-14 08:59:19 PDT
Created attachment 465915 [details]
Chrome

For comparison, the Console output in Chrome.
Comment 2 Thomas Steiner 2023-04-14 09:01:55 PDT
(Note that due to https://bugs.webkit.org/show_bug.cgi?id=255402 I had to `postMessage()` any logs from subworker.js to worker.js to see anything.)
Comment 4 Radar WebKit Bug Importer 2023-04-14 15:52:26 PDT
<rdar://problem/108069396>
Comment 5 Sihui Liu 2023-04-17 16:50:56 PDT
Pull request: https://github.com/WebKit/WebKit/pull/12833
Comment 6 EWS 2023-04-18 08:52:15 PDT
Committed 263075@main (808b1c7f159a): <https://commits.webkit.org/263075@main>

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