Skip to content

[Feature]: Support ArrayBuffer in IndexedDB when using BrowserContext#storageState #38915

@gwennlbh

Description

@gwennlbh

🚀 Feature Request

Serialize ArrayBuffer values into a base64-encoded bytestring instead of an empty array

For example, here's how devalue handles it:

{ bytes: new Uint8Array([1, 2, 3, 4]).buffer }

// becomes

[{"bytes":1},["ArrayBuffer","AQIDBA=="]]

An online demo: https://svelte.dev/playground/9d3f0802c85244fb8f3e136f9022a51c?version=5.48.0

Devalue is used for transfering data in server-client exchanges in SvelteKit. The 1 is because it also handles cyclical references, so there's index-based indirection, but the base64 idea is the same

If this is too much complexity, providing a hook for implementing a custom serializer/reviver (à la JSON.stringify's second argument) would work for me too

Either way, I'd be happy to contribue a PR, as I was really looking forward to making use of Storage States ^^

Example

Currently, objects containing ArrayBuffer values, such as:

{ bytes: new Uint8Array([1, 2, 3, 4]).buffer }

get encoded as such:

// origins[0].indexedDB[0].stores[0].records[0]
{
  "valueEncoded": {
    "o": [{ 
       "k": "bytes", 
       // empty array ↓
       "v": { "o": [], "id": 2 } 
    }]
}

Instead, they could be encoded into a base64 bytestring, there's even a standard Uint8Array#toBase64 now

Unfortunately it was just added to Node (It's on Node 25 only), but we can pretty easily do our own base64 encoding logic until support for Node <26 can be dropped (which will be in a while but whatever).

Here's devalue's implementation, for example

Motivation

I'm testing a local-only webapp that manipulates image data, and stores the image file bytes into indexedDB.

I was previously doing my own dataase dump/load via page.evaluate() but it is kind of slow (i need to do a full-page reload after loading a database dump before starting the test)

I was wondering if I could somehow "arm" the browser so that it already has everything in place in its IndexedDB

I followed the guide at https://playwright.dev/docs/auth#basic-shared-account-in-all-tests but upon looking at the .json the method writes, it looks like ArrayBuffers are not saved

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions