aklinker1 / webext-core

Collection of essential libraries and tools for building web extensions
https://webext-core.aklinker1.io
MIT License
96 stars 11 forks source link

Using @webext-core/proxy-service, the blob data transfer is empty #62

Closed AydenGen closed 1 month ago

AydenGen commented 1 month ago

Replication with examples/vanilla-indexed-db

  1. utils/todos-repo.ts

    export interface Todo {
    id: string;
    title: string;
    done?: boolean;
    + blob?: Blob
    }
  2. entrypoints/popup/main.ts

    (async () => {
    todosRepo.createOrUpdate({
    id: '2',
    title: 'Another TODO',
    +   blob: new Blob(['Blob TODO'], { type: 'text/plain' }),
    });
    
    const all = await todosRepo.getAll();
    console.log('All todos:', all);
    })();
  3. utils/todos-repo.ts

    
    async createOrUpdate(todo) {
    + console.log('createOrUpdate', todo);
    await (await db).put('todos', todo);
    },

4. output
```ts
{
  "id": "2",
  "title": "Another TODO",
  "blob": {} // The blob here is an empty object.
}
aklinker1 commented 1 month ago

This proxy uses the browser messaging APIs, which doesn't support class instances, like blobs. You can only pass primitives, arrays, or objects.

Transferring blobs is only supported by the window.postMessage API, which is completely unrelated to this library.