Skip to content

Commit

Permalink
fix: remove normalizeLinksContentScript (#836)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lidel authored Dec 12, 2019
1 parent c3f4c53 commit f31605b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 120 deletions.
2 changes: 1 addition & 1 deletion add-on/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
"description": "An option title on the Preferences screen (option_catchUnhandledProtocols_title)"
},
"option_catchUnhandledProtocols_description": {
"message": "Enables support for ipfs://, ipns:// and dweb: by normalizing links and requests done with unhandled protocols",
"message": "Enables provisional support for ipfs://, ipns:// and dweb: by redirecting unhandled address bar requests to an HTTP gateway",
"description": "An option description on the Preferences screen (option_catchUnhandledProtocols_description)"
},
"option_linkify_title": {
Expand Down
93 changes: 0 additions & 93 deletions add-on/src/contentScripts/normalizeLinksWithUnhandledProtocols.js

This file was deleted.

26 changes: 2 additions & 24 deletions add-on/src/lib/ipfs-companion.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ module.exports = async function init () {
if (!state.activeIntegrations(details.url)) return // skip if opt-out exists
// console.info(`[ipfs-companion] onDOMContentLoaded`, details)
if (state.linkify) {
console.info(`[ipfs-companion] Running linkfy experiment for ${details.url}`)
log(`running linkfy experiment on ${details.url}`)
try {
await browser.tabs.executeScript(details.tabId, {
file: '/dist/bundles/linkifyContentScript.bundle.js',
Expand All @@ -379,29 +379,7 @@ module.exports = async function init () {
runAt: 'document_idle'
})
} catch (error) {
console.error(`Unable to linkify DOM at '${details.url}' due to`, error)
}
}
if (state.catchUnhandledProtocols) {
// console.log(`[ipfs-companion] Normalizing links with unhandled protocols at ${tab.url}`)
// See: https://github.com/ipfs/ipfs-companion/issues/286
try {
// pass the URL of user-preffered public gateway
await browser.tabs.executeScript(details.tabId, {
code: `window.ipfsCompanionPubGwURL = '${state.pubGwURLString}'`,
matchAboutBlank: false,
allFrames: true,
runAt: 'document_start'
})
// inject script that normalizes `href` and `src` containing unhandled protocols
await browser.tabs.executeScript(details.tabId, {
file: '/dist/bundles/normalizeLinksContentScript.bundle.js',
matchAboutBlank: false,
allFrames: true,
runAt: 'document_end'
})
} catch (error) {
console.error(`Unable to normalize links at '${details.url}' due to`, error)
log.error(`Unable to linkify DOM at '${details.url}' due to`, error)
}
}
if (details.url.startsWith(state.webuiRootUrl)) {
Expand Down
3 changes: 1 addition & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ const contentScriptsConfig = merge(commonConfig, {
name: 'contentScripts',
entry: {
ipfsProxyContentScriptPayload: './add-on/src/contentScripts/ipfs-proxy/page.js',
linkifyContentScript: './add-on/src/contentScripts/linkifyDOM.js',
normalizeLinksContentScript: './add-on/src/contentScripts/normalizeLinksWithUnhandledProtocols.js'
linkifyContentScript: './add-on/src/contentScripts/linkifyDOM.js'
}
})

Expand Down

0 comments on commit f31605b

Please sign in to comment.