Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ServiceWorker-like protocol handlers for WebExtensions #212

Open
lidel opened this issue Sep 6, 2023 · 3 comments
Open

ServiceWorker-like protocol handlers for WebExtensions #212

lidel opened this issue Sep 6, 2023 · 3 comments
Labels
dif/expert Extensive knowledge (implications, ramifications) required effort/weeks Estimated to take multiple weeks env:browser epic P1 High: Likely tackled by core team if no one steps up specs

Comments

@lidel
Copy link
Member

lidel commented Sep 6, 2023

(this is placeholder issue, will be updated as we work on spec prototypes, discuss with vendors etc)

Problem

Currently (2023Q3):

  1. The web platform supports registering custom protocol handlers via navigator.registerProtocolHandler.
  2. WebExtensions in Firefox automate this and support registering custom protocol handlers via manifest.json/protocol_handlers
  3. (somehow related) PWA manifest (at least in Firefox?) also automates this via protocol_handlers field

The downside in all the three cases above is that foo:// registered this way can ONLY do HTTP redirect to some other HTTP URL. There is no built-in way to return bytes to the renderer process directly.

Web platform has a way to return a synthetic byte response with custom headers: register a ServiceWorker to resolve requests for specific scope and create Response objects.

Problem? Currently there is no way to leverage ServiceWorker for resolving protocols registered via manifest.json/protocol_handlers. Only redirect-based handlers are supported. ServiceWorker support is missing.

Prototyping Solution

There is an opportunity to streamline the UX/DX around registering protocol handlers via manifest of extension (2) or PWA (3).

Both PWAs and WebExtensions (with Manifest V3) already have ServiceWorker capabilities, but we could focus on WebExtensions as it is safer environment with more clear boundary and UX around installation.

What is missing, is the ability for a protocol handler foo:// to be a scope for a ServiceWorker that takes care of fullfiling all requests sent to the foo:// scheme.

If we had that, browser extensions or PWAs would be able to fetch content-addressed content from ipfs:// and perform hash verification on the client, the way that benefits user the most.

IPFS Use Case is for WebExtension

  • ipfs-companion WebExtension being able to use in-memory Helia (JS implementation of IPFS node) for resolving requests for IPFS content

References

@lidel lidel added specs epic dif/expert Extensive knowledge (implications, ramifications) required P1 High: Likely tackled by core team if no one steps up effort/weeks Estimated to take multiple weeks env:browser labels Sep 6, 2023
@lidel lidel changed the title ServiceWorker-like protocol handlers for PWA and WebExtensions ServiceWorker-like protocol handlers for WebExtensions/PWAs Sep 14, 2023
@lidel lidel changed the title ServiceWorker-like protocol handlers for WebExtensions/PWAs ServiceWorker-like protocol handlers for WebExtensions Sep 14, 2023
@lidel
Copy link
Member Author

lidel commented Dec 14, 2023

An important prerequisite for this work landed: automated testing of registerProtocolHandler Web API is now possible as part of Web Platform Tests (WPT):

"Real" WebExtension handler will be built as improvement on top of abstractions like registerProtocolHandler Web API, and having solid testing setup for these early foundations enables future work to be protected with regression-tests too.

@SgtPooki
Copy link
Member

SgtPooki commented Apr 9, 2024

Problem? Currently there is no way to leverage ServiceWorker for resolving protocols registered via manifest.json/protocol_handlers. Only redirect-based handlers are supported. ServiceWorker support is missing.

If we can handle redirects, then with https://github.com/ipfs-shipyard/service-worker-gateway we could simply redirect to inbrowser.tld

@lidel
Copy link
Member Author

lidel commented Apr 18, 2024

Yes, until we have better APIs, IPFS Companion will likely have a mode where it is using ServiceWorker on some public https:// server (with ability to self-host on own domain).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dif/expert Extensive knowledge (implications, ramifications) required effort/weeks Estimated to take multiple weeks env:browser epic P1 High: Likely tackled by core team if no one steps up specs
Projects
None yet
Development

No branches or pull requests

2 participants