metamask-filecoin-developer-beta
metamask-filecoin-developer-beta copied to clipboard
Add ipfs and ipns resolving support
This PR will enable Metamask users to resolve ipfs:// and ipns:// URLs (on browsers that don't have integrated support for this).
:warning: IMPORTANT :warning: For this feature to work properly, we should first merge fix #12
Browser support:
Brave and Opera already have native support for resolving ipfs://
and ipns://
, so there is no sense in providing these features.
Metamasks advanced settings have been expanded with a new category (Enable IPFS and IPNS URL resolving). When the user enables this feature, the browser will ask the user to give Metamask permission for handling IPFS and IPNS URLs. After this initial setup, the users' browser will resolve ipfs:// and ipns:// using gateway from settings.
Manual testing steps:
- Enable IPFS and IPNS URL resolving
- Resolve one valid IPFS and one valid IPNS URL
- Change gateway in settings (make sure new gateway is used)
- Disable IPFS and IPNS URL resolving (make sure that URLs are not still resolving)
Explanation of solution:
As chrome doesn't support setting protocol_handlers
as part of manifest definition, the only way to support URL resolving was to set protocol handler through code using window.navigator.registerProtocolHandler
. The limitation here was that it must be invoked from a page that will handle these requests. Because of this, when the user wants to turn on the URL resolving feature new view is shown and the protocol handler then registers on chrome-extension://<extension-id>/
. Now all ipfs://
and ipns://
requests are rerouted to extension and then handled by the onBeforeRequest
handler.
After metamask is installed, firefox handles ipfs://
and ipns://
requests by routing them to https://dweb.link/ipfs/...
Explanation of solution:
Same implementation as Chrome solution wasn't possible as Firefox doesn't allow setting permission for routing requests on extension page (moz-extension
), because of that it was impossible to invoke window.navigator.registerProtocolHandler
and mimic Chrome flow. On the other side, Firefox does support setting protocol_handlers
as part of manifest definition, so this was used to enable URL resolving. This solution does limit any kind of configuration or enabling/disabling this feature, it just registers protocol handlers when adding metamask.
I have read the CLA Document and I hereby sign the CLA
I have read the CLA Document and I hereby sign the CLA