feat(storageState): add OPFS support#41420
Conversation
6f6684c to
18b71cc
Compare
| } | ||
|
|
||
| // Getting a File object's contents requires async | ||
| export async function serializeFile(value: File): Promise<Extract<SerializedValue, { f: any; }>> { |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
| }; | ||
|
|
||
| type OPFSTree = Array< | ||
| [name: string, contents: Extract<SerializedValue, {f: any}> | OPFSTree] |
There was a problem hiding this comment.
Let's use conservative types:
type FSEntry {
type: 'file' | 'folder';
name: string;
lastModified: number;
}
type File = FSEntry & {
type: 'file';
base64: string;
}
type Folder = FSEntry & {
type: 'folder';
entries: (File | Folder)[];
}| { ta: { b: string, k: TypedArrayKind } } | | ||
| { ab: { b: string } }; | ||
| { ab: { b: string } } | | ||
| { f: { b: string, n: string, t: string, m: number } }; |
There was a problem hiding this comment.
You should be able to serialize and restore opfs without this.
| return base64ToTypedArray(value.ta.b, typedArrayConstructors[value.ta.k]); | ||
| if ('ab' in value) | ||
| return base64ToTypedArray(value.ab.b, Uint8Array).buffer; | ||
| if ('f' in value) { |
There was a problem hiding this comment.
I did it like this so that we would get File object support in IndexedDB as a side effect of the PR, but yeah it's not strictly necessary
|
|
||
| async storageState(params: channels.BrowserContextStorageStateParams, progress: Progress): Promise<channels.BrowserContextStorageStateResult> { | ||
| return await this._context.storageState(progress, params.indexedDB, params.credentials); | ||
| return await this._context.storageState(progress, params.indexedDB, params.credentials, params.opfs); |
bac24d8 to
e9d3564
Compare
e9d3564 to
2040049
Compare
|
i just realized, i don't think there's anyway to set the lastModified or content type of the file when writing it into OPFS. Maybe we should just leave them out of the serialized data :/ Unfortunate cuz tests can't rely on these things (esp. the last modified date could be useful, i feel like) I mean, they have a solution: mocking FileSystemFileHandle#getFile i guess |
Closes #41400