Goal of the demo
Demonstrate how an extension can create a blob in the extension's service worker and transfer it to a page's main world.
Suggested implementation
Sketch of my initial implementation plan
- Have a content script inject an iframe into a page
- Run a script in the iframe to post a message back to the service worker using
navigator.serviceWorker.controller.postMessage()
- In the SW's message handler, generate a blob OR use
structuredClone() to create a copy of a blob.
- Use
event.source.postMessage(msg, [transferable]) to reply to the client and transfer the blob
- In the iframe's message handler, use
window.parent.postMessage(msg, "<origin>", [transferable]) to transfer the data to the page
Related links
Notes
Initial findings suggest that it's not possible to transfer variables across origins. I'm tentatively thinking that to work around this, we can use URL.createObjectURL() in the iframe and directly reference the object URL somewhere that's easily visible to the end user (e.g. canvas, Audio/Video element, etc.).
Goal of the demo
Demonstrate how an extension can create a blob in the extension's service worker and transfer it to a page's main world.
Suggested implementation
Sketch of my initial implementation plan
navigator.serviceWorker.controller.postMessage()structuredClone()to create a copy of a blob.event.source.postMessage(msg, [transferable])to reply to the client and transfer the blobwindow.parent.postMessage(msg, "<origin>", [transferable])to transfer the data to the pageRelated links
Notes
Initial findings suggest that it's not possible to transfer variables across origins. I'm tentatively thinking that to work around this, we can use
URL.createObjectURL()in the iframe and directly reference the object URL somewhere that's easily visible to the end user (e.g. canvas, Audio/Video element, etc.).