Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mv3): adding dynamicNetRequest rule reconciliation logic + Firefox Builds #1186

Merged
merged 60 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
4dee9c6
feat(mv3): :sparkles: MV3 Manifest Migration
whizzzkid Mar 3, 2023
54e9edb
fix(mv3): :wastebasket: No longer needed
whizzzkid Mar 3, 2023
937e0f7
fix(mv3): :wrench: Corresponding MV3 Changes
whizzzkid Mar 3, 2023
2de3028
feat(mv3): :package: Adding deps
whizzzkid Mar 3, 2023
98622b7
feat(telemetry): Refactor Metrics Tracking from background service_wo…
whizzzkid Mar 13, 2023
274f7be
feat(mv3): :adhesive_bandage: Patch @protobufjs/inquire to not have eval
whizzzkid Mar 13, 2023
f5dcefd
fix(mv3): :alien: Fixing contextMenus API changes (#1177)
whizzzkid Mar 15, 2023
b05e120
fix(mv3): webpack configs (#1178)
whizzzkid Mar 23, 2023
6819356
feat(mv3): ✨ XHR to Fetch Migration (#1179)
whizzzkid Mar 23, 2023
36b7f74
Fix(mv3): Popup Was Broken (#1180)
whizzzkid Mar 23, 2023
0f99265
fix(mv3): :passport_control: Limiting permissions to chrome-extension
whizzzkid Mar 23, 2023
80dcb0d
Update add-on/src/lib/ipfs-companion.js
whizzzkid Mar 23, 2023
fc74226
fix(types): :label: Refactoring existing type declaration
whizzzkid Mar 23, 2023
4ca1cc0
fix(types): :label: Moving to new types path
whizzzkid Mar 23, 2023
9abfd6f
feat(types): :sparkles: Adding typescript support for transpilation
whizzzkid Mar 23, 2023
0c9aab4
feat(mv3): :sparkles: Adding blocking request tester
whizzzkid Mar 23, 2023
79ffc72
Merge branch 'rc/3.0-mv3' into feat/blocking-by-observing
whizzzkid Mar 24, 2023
f2c678b
fix(mv3): :adhesive_bandage: package.json
whizzzkid Mar 24, 2023
7029569
Merge branch 'rc/3.0-mv3' into feat/blocking-by-observing
whizzzkid Mar 24, 2023
bc07aa9
fix(mv3): :rotating_light: Fix Lint
whizzzkid Mar 24, 2023
abe9208
Merge branch 'rc/3.0-mv3' into feat/blocking-by-observing
whizzzkid Mar 24, 2023
9736b1e
Merge branch 'rc/3.0-mv3' into feat/blocking-by-observing
whizzzkid Mar 24, 2023
be24e8f
fix: :rotating_light: fix lint
whizzzkid Mar 24, 2023
4c3eeb3
fix(mv3): :adhesive_bandage: temp fix to build background context
whizzzkid Mar 27, 2023
7431da1
fix(mv3): :necktie: Detection Logic for MV3 world.
whizzzkid Mar 27, 2023
d8538fa
feat(mv3): :sparkles: Dynamic RegexSubstitution
whizzzkid Mar 28, 2023
dcd51df
fix(types): :arrow_up: Adding .mocharc.json to fix mocha for TS.
whizzzkid Mar 29, 2023
b2dcfeb
fix: :rotating_light: Lint Fix
whizzzkid Mar 29, 2023
27ea2c3
fix(mv3): :recycle: refactor background.service_worker
whizzzkid Mar 29, 2023
78c072a
feat(mv3): :sparkles: Passing state to BlockOrObserve
whizzzkid Mar 30, 2023
04dc26b
fix(recovery): :bug: conditional for recovery
whizzzkid Mar 30, 2023
3d76720
fix: :wastebasket: unneeded @ts-ignore
whizzzkid Apr 4, 2023
3d80737
fix: :bulb: Adding comments
whizzzkid Apr 4, 2023
66e9d9b
fix: fixing string method.
whizzzkid Apr 4, 2023
937e3d0
fix: removing extra space.
whizzzkid Apr 4, 2023
47f5335
fix: removing @ts-nocheck
whizzzkid Apr 4, 2023
62537c0
no longer needed
whizzzkid Apr 4, 2023
9bdd4f3
fix(mv3): :recycle: Refactor
whizzzkid Apr 4, 2023
2d2124c
feat(mv3): :sparkles: Adding rule-recon logic
whizzzkid Apr 4, 2023
1692d5b
saving state
whizzzkid Apr 18, 2023
cbe7f47
Merge branch 'rc/3.0-mv3' into fix/reconcile-logic
whizzzkid Apr 28, 2023
9d76b7c
fix(mv3): :wrench: Manifest
whizzzkid Apr 28, 2023
d3c80a7
fix(mv3): :wrench: Fixing firefox webpack config
whizzzkid May 1, 2023
8e6ad0c
fix(mv3): :adhesive_bandage: Patching debug to use in memory store in…
whizzzkid May 1, 2023
6dfbd51
fix: :rotating_light: fixing lint and moving from record type to map …
whizzzkid May 3, 2023
7fbbac7
fix: :memo: Adding docstrings.
whizzzkid May 3, 2023
10f2c1f
fix(mv3): :poop: web-ext making things harder than it needs to be.
whizzzkid May 3, 2023
c5e7729
fix(mv3): :rewind: no more debug patching
whizzzkid May 4, 2023
95acf45
fix(mv3): :poop: improved recon logic
whizzzkid May 4, 2023
1a88690
fix: :memo: adding comments regarding debug.
whizzzkid May 4, 2023
39cabc9
fix: :rotating_light: Fix lint
whizzzkid May 4, 2023
600f3ef
fix(mv3): :passport_control: manifest perms
whizzzkid May 4, 2023
7c18723
fix: :wastebasket: unnecessary blank line
whizzzkid May 4, 2023
d04d341
feat(mv3): :test_tube: Adding initial tests
whizzzkid May 5, 2023
27c760b
feat(mv3): :clown_face: Adding Mock DeclarativeNetRequest Implementation
whizzzkid May 5, 2023
aef128a
nits
whizzzkid May 5, 2023
eb96110
fix: adding more test examples
whizzzkid May 9, 2023
dcd5d5e
fix: self-documenting code.
whizzzkid May 9, 2023
e5ba415
fix: unneeded comment
whizzzkid May 9, 2023
befad2f
Update test/functional/lib/redirect-handler/blockOrObserve.test.ts
whizzzkid May 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions add-on/manifest.chromium.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"minimum_chrome_version": "101",
"minimum_chrome_version": "111",
"background": {
"service_worker": "dist/bundles/backgroundPage.bundle.js"
},
"permissions": [
"clipboardWrite",
"contextMenus",
Expand All @@ -13,6 +16,5 @@
"declarativeNetRequest",
"declarativeNetRequestFeedback"
],
"host_permissions": ["<all_urls>"],
"incognito": "not_allowed"
}
8 changes: 2 additions & 6 deletions add-on/manifest.common.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
"description": "__MSG_manifest_extensionDescription__",
"homepage_url": "https://github.com/ipfs-shipyard/ipfs-companion",
"author": "IPFS Community",
"background": {
"service_worker": "dist/bundles/backgroundPage.bundle.js"
},
"icons": {
"19": "icons/png/ipfs-logo-on_19.png",
"38": "icons/png/ipfs-logo-on_38.png",
Expand All @@ -28,6 +25,7 @@
"browser_style": false,
"page": "dist/options/options.html"
},
"host_permissions": ["<all_urls>"],
"web_accessible_resources": [
{
"resources": [
Expand All @@ -40,9 +38,7 @@
"dist/recovery/recovery.html",
"dist/recovery/recovery.js"
],
"matches": [
"<all_urls>"
]
"matches": ["<all_urls>"]
}
],
"content_security_policy": {
Expand Down
2 changes: 1 addition & 1 deletion add-on/manifest.firefox-beta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"browser_specific_settings": {
"gecko": {
"id": "[email protected]",
"update_url": "https://ipfs-shipyard.github.io/ipfs-companion/ci/firefox/update.json"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to remove the update_url?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this is no longer supported.

"strict_min_version": "111.0.0"
}
}
}
6 changes: 4 additions & 2 deletions add-on/manifest.firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
"options_ui": {
"browser_style": false
},
"background": {
"scripts": ["dist/bundles/backgroundPage.firefox.bundle.js"]
},
"browser_specific_settings": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "109.0.0"
"strict_min_version": "111.0.0"
}
},
"permissions": [
"<all_urls>",
"idle",
"tabs",
"notifications",
Expand Down
35 changes: 16 additions & 19 deletions add-on/src/lib/ipfs-companion.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ import { registerSubdomainProxy } from './http-proxy.js'
import { runPendingOnInstallTasks } from './on-installed.js'
import { getExtraInfoSpec } from './redirect-handler/blockOrObserve.js'

// this won't work in webworker context. Needs to be enabled manually
// https://github.com/debug-js/debug/issues/916
const log = debug('ipfs-companion:main')
log.error = debug('ipfs-companion:main:error')

let browserActionPort // reuse instance for status updates between on/off toggles

// init happens on addon load in background/background.js
export default async function init (windowedContext = false) {
export default async function init () {
// INIT
// ===================================================================
let ipfs // ipfs-api instance
Expand Down Expand Up @@ -79,23 +81,19 @@ export default async function init (windowedContext = false) {
copier = createCopier(notify, ipfsPathValidator)
ipfsImportHandler = createIpfsImportHandler(getState, getIpfs, ipfsPathValidator, runtime, copier)
inspector = createInspector(notify, ipfsPathValidator, getState)
if (!windowedContext) {
contextMenus = createContextMenus(getState, runtime, ipfsPathValidator, {
onAddFromContext,
onCopyCanonicalAddress: copier.copyCanonicalAddress,
onCopyRawCid: copier.copyRawCid,
onCopyAddressAtPublicGw: copier.copyAddressAtPublicGw
})
modifyRequest = createRequestModifier(getState, dnslinkResolver, ipfsPathValidator, runtime)
log('register all listeners')
registerListeners()
await registerSubdomainProxy(getState, runtime, notify)
log('init done')
setApiStatusUpdateInterval(options.ipfsApiPollMs)
await runPendingOnInstallTasks()
} else {
log('init done (windowed context)')
}
contextMenus = createContextMenus(getState, runtime, ipfsPathValidator, {
onAddFromContext,
onCopyCanonicalAddress: copier.copyCanonicalAddress,
onCopyRawCid: copier.copyRawCid,
onCopyAddressAtPublicGw: copier.copyAddressAtPublicGw
})
modifyRequest = createRequestModifier(getState, dnslinkResolver, ipfsPathValidator, runtime)
log('register all listeners')
registerListeners()
await registerSubdomainProxy(getState, runtime, notify)
log('init done')
setApiStatusUpdateInterval(options.ipfsApiPollMs)
await runPendingOnInstallTasks()
} catch (error) {
log.error('Unable to initialize addon due to error', error)
if (notify) notify('notify_addonIssueTitle', 'notify_addonIssueMsg')
Expand All @@ -120,7 +118,6 @@ export default async function init (windowedContext = false) {
onBeforeSendInfoSpec.push('extraHeaders')
}
browser.webRequest.onBeforeSendHeaders.addListener(

onBeforeSendHeaders, { urls: ['<all_urls>'] }, getExtraInfoSpec(onBeforeSendInfoSpec))
browser.webRequest.onBeforeRequest.addListener(onBeforeRequest, { urls: ['<all_urls>'] }, getExtraInfoSpec())
browser.webRequest.onHeadersReceived.addListener(onHeadersReceived, { urls: ['<all_urls>'] }, getExtraInfoSpec(['responseHeaders']))
Expand Down
53 changes: 27 additions & 26 deletions add-on/src/lib/ipfs-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { dropSlash, ipfsUri, pathAtHttpGateway, sameGateway } from './ipfs-path.
import { safeURL } from './options.js'
import { braveNodeType } from './ipfs-client/brave.js'
import { recoveryPagePath } from './constants.js'
import { addRuleToDynamicRuleSetGenerator, supportsBlock } from './redirect-handler/blockOrObserve.js'
import { addRuleToDynamicRuleSetGenerator, isLocalHost, supportsBlock } from './redirect-handler/blockOrObserve.js'

const log = debug('ipfs-companion:request')
log.error = debug('ipfs-companion:request:error')
Expand Down Expand Up @@ -100,7 +100,7 @@ export function createRequestModifier (getState, dnslinkResolver, ipfsPathValida
ignore(request.requestId)
}
// skip all local requests
if (request.url.startsWith('http://127.0.0.1') || request.url.startsWith('http://localhost') || request.url.startsWith('http://[::1]')) {
if (isLocalHost(request.url)) {
ignore(request.requestId)
}

Expand Down Expand Up @@ -160,23 +160,19 @@ export function createRequestModifier (getState, dnslinkResolver, ipfsPathValida
// take advantage of subdomain redirect provided by go-ipfs >= 0.5
if (state.redirect && request.type === 'main_frame' && sameGateway(request.url, state.gwURL)) {
const redirectUrl = safeURL(request.url, { useLocalhostName: state.useSubdomains }).toString()
if (redirectUrl !== request.url) {
return handleRedirection({
originUrl: request.url,
redirectUrl
})
}
return handleRedirection({
originUrl: request.url,
redirectUrl
})
}

// For now normalize API to the IP to comply with go-ipfs checks
if (state.redirect && request.type === 'main_frame' && sameGateway(request.url, state.apiURL)) {
const redirectUrl = safeURL(request.url, { useLocalhostName: false }).toString()
if (redirectUrl !== request.url) {
return handleRedirection({
originUrl: request.url,
redirectUrl
})
}
return handleRedirection({
originUrl: request.url,
redirectUrl
})
}

// early sanity checks
Expand Down Expand Up @@ -476,13 +472,21 @@ export function createRequestModifier (getState, dnslinkResolver, ipfsPathValida
}
}

/**
* Handles redirection in MV2 and MV3.
*
* @param {object} input contains originUrl and redirectUrl.
* @returns
*/
function handleRedirection ({ originUrl, redirectUrl }) {
if (supportsBlock) {
return { redirectUrl }
}
if (redirectUrl !== '' && originUrl !== '' && redirectUrl !== originUrl) {
if (supportsBlock) {
return { redirectUrl }
}

// Let browser handle redirection MV3 style.
addRuleToDynamicRuleSet({ originUrl, redirectUrl })
// Let browser handle redirection MV3 style.
addRuleToDynamicRuleSet({ originUrl, redirectUrl })
}
}

// Returns a string with URL at the active gateway (local or public)
Expand Down Expand Up @@ -532,13 +536,10 @@ async function redirectToGateway (request, url, state, ipfsPathValidator, runtim
}
}

// return a redirect only if URL changed
if (redirectUrl && request.url !== redirectUrl) {
return handleRedirection({
originUrl: request.url,
redirectUrl
})
}
return handleRedirection({
originUrl: request.url,
redirectUrl
})
}

function isSafeToRedirect (request, runtime) {
Expand Down
Loading