You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/how-to/detect-ipfs-on-web.md
+25-24
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,24 @@
1
-
# Discover IPFS content from web2
1
+
---
2
+
title: Discover IPFS content from Web2
3
+
description: Learn how to add support for content-addressed IPFS resources in web browsers and other user agents.
4
+
---
2
5
3
-
Below is the suggested heuristic for detecting content-addressed resources on the web, and presenting additional user interface for interacting with that content.
6
+
# Discover IPFS content from Web2
4
7
5
-
The goal of this page is to provide some suggestions and best practices for web browsers and other [user agents](https://en.wikipedia.org/wiki/User_agent) that are interested in adding support for [content-addressed resources on the Web](/how-to/address-ipfs-on-web).
8
+
The goal of this page is to provide some suggestions and best practices for Web 2 web browsers and other [user agents](https://en.wikipedia.org/wiki/User_agent) that are interested in adding support for [content-addressed resources](/how-to/address-ipfs-on-web).
6
9
7
10
## Detecting content-addressed resources
8
11
9
-
In many cases IPFS resources can be detected just by looking at the URI, especially if it is an HTTP URL pointing at a public gateway. This allows a browser to upgrade the transport protocol to IPFS, and remove the need for sending an HTTP request to a remote server.
12
+
In many cases, IPFS resources can be detected just by looking at the URI, especially if it is an HTTP URL pointed at a public gateway. This allows a browser to upgrade the transport protocol to IPFS, and removes the need to send an HTTP request to a remote server.
10
13
11
-
The high level heuristic is to check, in order:
12
-
- Does the `URL` follow [path or subdomain gateway](/how-to/address-ipfs-on-web/) convention?
13
-
- If not, does [DNSLink](/concepts/dnslink/) with an IPFS path exist for `URL.hostname`?
14
+
### Methodology
14
15
15
-
If any of the above is true, a user agent should be able to find a content path that can be used for data retrieval over IPFS. See the illustration below.
16
+
To determine if a resource is an IPFS resource, answer the following questions in order:
17
+
18
+
1. Does the `URL` follow [path or subdomain gateway](/how-to/address-ipfs-on-web/) convention?
19
+
1. If not, does [DNSLink](/concepts/dnslink/) with an IPFS path exist for `URL.hostname`?
20
+
21
+
If you answered yes to either of the above questions, a user agent should be able to find a content path that can be used for data retrieval over IPFS, as described in the illustration below:
16
22
17
23
```mermaid
18
24
flowchart TD
@@ -77,7 +83,9 @@ flowchart TD
77
83
PathFromHeader --> PotentialContentPath
78
84
```
79
85
80
-
## What to do with detected paths?
86
+
## What to do with detected paths
87
+
88
+
What you do with the detected IPFS resource path depends on the type of path.
81
89
82
90
### Immutable `/ipfs/cid/..`
83
91
@@ -101,27 +109,20 @@ flowchart TD
101
109
102
110
## FAQ
103
111
104
-
- What if a browser does not support `ipfs://` and `ipns://` natively?
105
-
- Implementation can use a [HTTP Gateway](/reference/http/gateway/) as a fallback: convert them to `//gatewayhost/ipxs/id/..` paths, or leverage the built-in URI router at `//gatewayhost/ipfs/?uri=%s`
106
-
- Why should `?query` or `#hash` from the original HTTP URL be preserved?
107
-
- Link could point at specific `#section` of a longer article. It is also common for JS running on a page to use `?query` and `#hash` for navigation and ad-hoc storage for some state.
108
-
- Should user agent redirect when URL does not match gateway convention, `URL.hostname` does not have a valid DNSLink, but `X-Ipfs-Path` is present in HTTP response AND points at immutable `/ipfs/cid`?
109
-
- This is an edge case, and we've seen that it is often a misconfiguration caused by invalid/missing DNSLink that could lead to bad UX when automatic redirect is involved: user ends up on immutable copy of a website, bookmark it or keep tab open, and miss updates when DNSLink setup is fixed.
110
-
- It is suggested to not redirect this edge case, or provide a setting that controls this type of redirect. Usually, showing "Open via IPFS" in the user interface is enough for this case.
112
+
**What if a browser does not support `ipfs://` and `ipns://` natively?** Implementations can use an [HTTP Gateway](/reference/http/gateway/) as a fallback, convert ththe path to `//gatewayhost/ipxs/id/..`-type paths, or leverage the built-in URI router at `//gatewayhost/ipfs/?uri=%s`
113
+
114
+
**Why should `?query` or `#hash` from the original HTTP URL be preserved?** The link could point at specific `#section` of a longer article. It is also common for JavaScript running on a page to use the `?query` and `#hash` for navigation and ad-hoc storage of some state.
115
+
116
+
**Should a user agent redirect when the URL does not match gateway convention, `URL.hostname` does not have a valid DNSLink, but `X-Ipfs-Path` is present in HTTP response AND points at an immutable `/ipfs/cid`?** This is an edge case, and we've seen that it is often a misconfiguration caused by an invalid or missing DNSLink that could lead to bad UX when automatic redirect is involved. The user ends up on an immutable copy of a website, bookmarks it or keeps tabs open, and misses updates when DNSLink setup is fixed. It is suggested to not redirect this edge case, or provide a setting that controls this type of redirect. Usually, showing "Open via IPFS" in the user interface is enough for this case.
111
117
112
118
## Implementation examples
113
119
114
120
### Brave
115
121
116
-
[IPFS is supported in Brave since 2021](https://brave.com/brave-integrates-ipfs/). Current features include `ipfs://` and `ipns://` URI support, ability to resolve them using a public or local gateway, opt-in Gateway and DNSLink redirects, and "Open via IPFS" button in the address bar:
122
+
[Brave has supported IPFS since 2021](https://brave.com/brave-integrates-ipfs/). Current features include `ipfs://` and `ipns://` URI support, ability to resolve this type of address using a public / local gateway, opt-in Gateway and/or DNSLink redirects, and an **Open via IPFS** button in the address bar:
117
123
118
-
> 
124
+
> 
119
125
120
126
### IPFS Companion
121
127
122
-
Firefox and Chromium-based browsers such as Google Chrome, Microsoft Edge can be augumented with [IPFS Companion](/install/ipfs-companion/) browser extension.
123
-
124
-
It provides detection of IPFS resources, redirect functionality, and a handy UI:
125
-
126
-
> 
127
-
128
+
Firefox and Chromium-based browsers such as Google Chrome or Microsoft Edge can be augumented with [IPFS Companion](/install/ipfs-companion/) browser extension, which allows them to detect IPFS content.
0 commit comments