Skip to content
This repository was archived by the owner on Mar 26, 2024. It is now read-only.
This repository was archived by the owner on Mar 26, 2024. It is now read-only.

Exposing API instance when embedded via iframe #30

Open
@lidel

Description

@lidel

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:
      1. App e.g. peerpad.net can register own service worker.
      2. App can embed hidden iframe for ipfs.io which registers IPFS node as service worker.
      3. App obtains MessagePort though iframe from ipfs.io service worker and transfers it to own service worker.
      4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions