This repository was archived by the owner on May 12, 2022. It is now read-only.
Add ipfs and ipns resolving support#13
Open
MakMuftic wants to merge 16 commits intoMetaMask:developfrom
Open
Conversation
Author
|
I have read the CLA Document and I hereby sign the CLA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR will enable Metamask users to resolve ipfs:// and ipns:// URLs (on browsers that don't have integrated support for this).
For this feature to work properly, we should first merge fix #12
Browser support:
Brave and Opera already have native support for resolving
ipfs://andipns://, 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:
Explanation of solution:
As chrome doesn't support setting
protocol_handlersas part of manifest definition, the only way to support URL resolving was to set protocol handler through code usingwindow.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 onchrome-extension://<extension-id>/. Now allipfs://andipns://requests are rerouted to extension and then handled by theonBeforeRequesthandler.After metamask is installed, firefox handles
ipfs://andipns://requests by routing them tohttps://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 invokewindow.navigator.registerProtocolHandlerand mimic Chrome flow. On the other side, Firefox does support settingprotocol_handlersas 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