Exposing API instance when embedded via iframe #30
Description
Part of ipfs/in-web-browsers#55
Background
I remember having a brief discussion about this workaround with someone in the past but I think we were hoping foreign fetch will land, so it never went anywhere. Now that foreign fetch got removed from ServiceWorker spec we should revisit and look into this once again.
Summary
So the idea is we could avoid having multiple instances of js-ipfs being spawned by ipfs-service-workers running on multiple pages by exposing API of a single service-worker-gateway's instance (eg. js.ipfs.io) over iframe's postMessage+ipfs-postmsg-proxy making all those SW instances talk to that one js-ipfs instance instead of spawning their own.
Example
Additional context extracted from arewedistributedyet/arewedistributedyet#32 (comment):
Use of "iframe + SW" as I described earlier was also proposed. I was also pointed out that "embedding limitation" I was concerned with could be addressed in few different ways:
- Embedding images or other self contained files isn't a huge deal you could obtain ArrayBuffer for it and then make blob url to embed.
- For things like CSS / JS that imports other stuff, little more tricky but doable sever steps:
- App e.g. peerpad.net can register own service worker.
- App can embed hidden iframe for
ipfs.io
which registers IPFS node as service worker.- App obtains
MessagePort
though iframe fromipfs.io
service worker and transfers it to own service worker.- Now two service workers have message channel for direct exchange which allows peerpad.net to serve any content from IPFS through it's SW by forwarding data from message channel.
Prior Discussions
@daviddias @vasco-santos I think this was discussed before, do you remember if there were any technical blockers or open problems that made this not feasible? Or is it ok to look into this?