Skip to content

Commit f31605b

Browse files
authored
fix: remove normalizeLinksContentScript (#836)
The script was responsible for overriding all src and href in DOM of every page to ensure content addressed with ipfs:// URL loads. Looking back, it does not align well with our upgrade path, and the result across browser vendors was buggy. While it allowed loading simple images, it did not help with broken XHR and iframe quirks and introduced unnecessary battery drain. Due to this, it is better to remove it and advise users to use content-addressing at a public gateway. This way everything works for people without IPFS client, and browsers with IPFS support can easily detect it and upgrade the call.
1 parent c3f4c53 commit f31605b

File tree

4 files changed

+4
-120
lines changed

4 files changed

+4
-120
lines changed

add-on/_locales/en/messages.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@
380380
"description": "An option title on the Preferences screen (option_catchUnhandledProtocols_title)"
381381
},
382382
"option_catchUnhandledProtocols_description": {
383-
"message": "Enables support for ipfs://, ipns:// and dweb: by normalizing links and requests done with unhandled protocols",
383+
"message": "Enables provisional support for ipfs://, ipns:// and dweb: by redirecting unhandled address bar requests to an HTTP gateway",
384384
"description": "An option description on the Preferences screen (option_catchUnhandledProtocols_description)"
385385
},
386386
"option_linkify_title": {

add-on/src/contentScripts/normalizeLinksWithUnhandledProtocols.js

-93
This file was deleted.

add-on/src/lib/ipfs-companion.js

+2-24
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ module.exports = async function init () {
370370
if (!state.activeIntegrations(details.url)) return // skip if opt-out exists
371371
// console.info(`[ipfs-companion] onDOMContentLoaded`, details)
372372
if (state.linkify) {
373-
console.info(`[ipfs-companion] Running linkfy experiment for ${details.url}`)
373+
log(`running linkfy experiment on ${details.url}`)
374374
try {
375375
await browser.tabs.executeScript(details.tabId, {
376376
file: '/dist/bundles/linkifyContentScript.bundle.js',
@@ -379,29 +379,7 @@ module.exports = async function init () {
379379
runAt: 'document_idle'
380380
})
381381
} catch (error) {
382-
console.error(`Unable to linkify DOM at '${details.url}' due to`, error)
383-
}
384-
}
385-
if (state.catchUnhandledProtocols) {
386-
// console.log(`[ipfs-companion] Normalizing links with unhandled protocols at ${tab.url}`)
387-
// See: https://github.com/ipfs/ipfs-companion/issues/286
388-
try {
389-
// pass the URL of user-preffered public gateway
390-
await browser.tabs.executeScript(details.tabId, {
391-
code: `window.ipfsCompanionPubGwURL = '${state.pubGwURLString}'`,
392-
matchAboutBlank: false,
393-
allFrames: true,
394-
runAt: 'document_start'
395-
})
396-
// inject script that normalizes `href` and `src` containing unhandled protocols
397-
await browser.tabs.executeScript(details.tabId, {
398-
file: '/dist/bundles/normalizeLinksContentScript.bundle.js',
399-
matchAboutBlank: false,
400-
allFrames: true,
401-
runAt: 'document_end'
402-
})
403-
} catch (error) {
404-
console.error(`Unable to normalize links at '${details.url}' due to`, error)
382+
log.error(`Unable to linkify DOM at '${details.url}' due to`, error)
405383
}
406384
}
407385
if (details.url.startsWith(state.webuiRootUrl)) {

webpack.config.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ const contentScriptsConfig = merge(commonConfig, {
141141
name: 'contentScripts',
142142
entry: {
143143
ipfsProxyContentScriptPayload: './add-on/src/contentScripts/ipfs-proxy/page.js',
144-
linkifyContentScript: './add-on/src/contentScripts/linkifyDOM.js',
145-
normalizeLinksContentScript: './add-on/src/contentScripts/normalizeLinksWithUnhandledProtocols.js'
144+
linkifyContentScript: './add-on/src/contentScripts/linkifyDOM.js'
146145
}
147146
})
148147

0 commit comments

Comments
 (0)