-
Notifications
You must be signed in to change notification settings - Fork 325
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): blocking by observing #1181
Merged
Merged
Changes from 29 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
4dee9c6
feat(mv3): :sparkles: MV3 Manifest Migration
whizzzkid 54e9edb
fix(mv3): :wastebasket: No longer needed
whizzzkid 937e0f7
fix(mv3): :wrench: Corresponding MV3 Changes
whizzzkid 2de3028
feat(mv3): :package: Adding deps
whizzzkid 98622b7
feat(telemetry): Refactor Metrics Tracking from background service_wo…
whizzzkid 274f7be
feat(mv3): :adhesive_bandage: Patch @protobufjs/inquire to not have eval
whizzzkid f5dcefd
fix(mv3): :alien: Fixing contextMenus API changes (#1177)
whizzzkid b05e120
fix(mv3): webpack configs (#1178)
whizzzkid 6819356
feat(mv3): ✨ XHR to Fetch Migration (#1179)
whizzzkid 36b7f74
Fix(mv3): Popup Was Broken (#1180)
whizzzkid 0f99265
fix(mv3): :passport_control: Limiting permissions to chrome-extension
whizzzkid 80dcb0d
Update add-on/src/lib/ipfs-companion.js
whizzzkid fc74226
fix(types): :label: Refactoring existing type declaration
whizzzkid 4ca1cc0
fix(types): :label: Moving to new types path
whizzzkid 9abfd6f
feat(types): :sparkles: Adding typescript support for transpilation
whizzzkid 0c9aab4
feat(mv3): :sparkles: Adding blocking request tester
whizzzkid 79ffc72
Merge branch 'rc/3.0-mv3' into feat/blocking-by-observing
whizzzkid f2c678b
fix(mv3): :adhesive_bandage: package.json
whizzzkid 7029569
Merge branch 'rc/3.0-mv3' into feat/blocking-by-observing
whizzzkid bc07aa9
fix(mv3): :rotating_light: Fix Lint
whizzzkid abe9208
Merge branch 'rc/3.0-mv3' into feat/blocking-by-observing
whizzzkid 9736b1e
Merge branch 'rc/3.0-mv3' into feat/blocking-by-observing
whizzzkid be24e8f
fix: :rotating_light: fix lint
whizzzkid 4c3eeb3
fix(mv3): :adhesive_bandage: temp fix to build background context
whizzzkid 7431da1
fix(mv3): :necktie: Detection Logic for MV3 world.
whizzzkid d8538fa
feat(mv3): :sparkles: Dynamic RegexSubstitution
whizzzkid dcd51df
fix(types): :arrow_up: Adding .mocharc.json to fix mocha for TS.
whizzzkid b2dcfeb
fix: :rotating_light: Lint Fix
whizzzkid 27ea2c3
fix(mv3): :recycle: refactor background.service_worker
whizzzkid 78c072a
feat(mv3): :sparkles: Passing state to BlockOrObserve
whizzzkid 04dc26b
fix(recovery): :bug: conditional for recovery
whizzzkid 3d76720
fix: :wastebasket: unneeded @ts-ignore
whizzzkid 3d80737
fix: :bulb: Adding comments
whizzzkid 66e9d9b
fix: fixing string method.
whizzzkid 937e3d0
fix: removing extra space.
whizzzkid 47f5335
fix: removing @ts-nocheck
whizzzkid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"diff": true, | ||
"extensions": [".js", ".ts"], | ||
"package": "./package.json", | ||
"require": [ | ||
"ignore-styles", | ||
"ts-node/register", | ||
"tsconfig-paths/register" | ||
], | ||
"exit": true, | ||
"recursive": true, | ||
"node-option": [ | ||
"es-module-specifier-resolution=node", | ||
"experimental-specifier-resolution=node", | ||
"loader=ts-node/esm" | ||
] | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
'use strict' | ||
/* eslint-env browser, webextensions */ | ||
|
||
// @ts-ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prefer @ts-expect-error instead of ts-ignore, but why do we need this? debug should have types IIRC There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
import debug from 'debug' | ||
|
||
import browser from 'webextension-polyfill' | ||
|
@@ -23,6 +24,8 @@ import createRuntimeChecks from './runtime-checks.js' | |
import { createContextMenus, findValueForContext, contextMenuCopyAddressAtPublicGw, contextMenuCopyRawCid, contextMenuCopyCanonicalAddress, contextMenuViewOnGateway, contextMenuCopyPermalink, contextMenuCopyCidAddress } from './context-menus.js' | ||
import { registerSubdomainProxy } from './http-proxy.js' | ||
import { runPendingOnInstallTasks } from './on-installed.js' | ||
import { getExtraInfoSpec } from './redirect-handler/blockOrObserve.js' | ||
|
||
const log = debug('ipfs-companion:main') | ||
log.error = debug('ipfs-companion:main:error') | ||
|
||
|
@@ -33,7 +36,7 @@ export default async function init (windowedContext = false) { | |
// INIT | ||
// =================================================================== | ||
let ipfs // ipfs-api instance | ||
/** @type {import('../types.js').CompanionState} */ | ||
/** @type {import('../types/companion.js').CompanionState} */ | ||
let state // avoid redundant API reads by utilizing local cache of various states | ||
let dnslinkResolver | ||
let ipfsPathValidator | ||
|
@@ -54,6 +57,7 @@ export default async function init (windowedContext = false) { | |
await migrateOptions(browser.storage.local, debug) | ||
const options = await browser.storage.local.get(optionDefaults) | ||
runtime = await createRuntimeChecks(browser) | ||
// @ts-ignore | ||
state = initState(options) | ||
notify = createNotifier(getState) | ||
|
||
|
@@ -65,6 +69,7 @@ export default async function init (windowedContext = false) { | |
console.error('[ipfs-companion] Failed to init IPFS client', err) | ||
notify( | ||
'notify_startIpfsNodeErrorTitle', | ||
// @ts-ignore | ||
whizzzkid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
err.name === 'ValidationError' ? err.details[0].message : err.message | ||
) | ||
} | ||
|
@@ -115,9 +120,11 @@ export default async function init (windowedContext = false) { | |
// Note: we need this for code ensuring kubo-rpc-client can talk to API without setting CORS | ||
onBeforeSendInfoSpec.push('extraHeaders') | ||
} | ||
browser.webRequest.onBeforeSendHeaders.addListener(onBeforeSendHeaders, { urls: ['<all_urls>'] }, onBeforeSendInfoSpec) | ||
browser.webRequest.onBeforeRequest.addListener(onBeforeRequest, { urls: ['<all_urls>'] }) | ||
browser.webRequest.onHeadersReceived.addListener(onHeadersReceived, { urls: ['<all_urls>'] }, ['responseHeaders']) | ||
browser.webRequest.onBeforeSendHeaders.addListener( | ||
// @ts-ignore | ||
whizzzkid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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'])) | ||
browser.webRequest.onErrorOccurred.addListener(onErrorOccurred, { urls: ['<all_urls>'], types: ['main_frame'] }) | ||
browser.webRequest.onCompleted.addListener(onCompleted, { urls: ['<all_urls>'], types: ['main_frame'] }) | ||
browser.storage.onChanged.addListener(onStorageChange) | ||
|
@@ -307,6 +314,7 @@ export default async function init (windowedContext = false) { | |
} | ||
// console.log('onAddFromContext.context', context) | ||
// console.log('onAddFromContext.fetchOptions', fetchOptions) | ||
// @ts-ignore | ||
whizzzkid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const response = await fetch(dataSrc, fetchOptions) | ||
const blob = await response.blob() | ||
const url = new URL(response.url) | ||
|
@@ -315,6 +323,7 @@ export default async function init (windowedContext = false) { | |
? url.hostname | ||
: url.pathname.replace(/[\\/]+$/, '').split('/').pop() | ||
data = { | ||
// @ts-ignore | ||
whizzzkid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
path: decodeURIComponent(filename), | ||
content: blob | ||
} | ||
|
@@ -332,13 +341,15 @@ export default async function init (windowedContext = false) { | |
} | ||
} catch (error) { | ||
console.error('Error in import to IPFS context menu', error) | ||
// @ts-ignore | ||
whizzzkid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (error.message === 'NetworkError when attempting to fetch resource.') { | ||
notify('notify_importErrorTitle', 'notify_importTrackingProtectionErrorMsg') | ||
console.warn('IPFS import often fails because remote file can not be downloaded due to Tracking Protection. See details at: https://github.com/ipfs/ipfs-companion/issues/227') | ||
browser.tabs.create({ | ||
url: 'https://github.com/ipfs/ipfs-companion/issues/227' | ||
}) | ||
} else { | ||
// @ts-ignore | ||
whizzzkid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
notify('notify_importErrorTitle', 'notify_inlineErrorMsg', `${error.message}`) | ||
} | ||
} | ||
|
@@ -524,6 +535,7 @@ export default async function init (windowedContext = false) { | |
// Chromium does not support SVG [ticket below is 8 years old, I can't even..] | ||
// https://bugs.chromium.org/p/chromium/issues/detail?id=29683 | ||
// Still, we want icon, so we precompute rasters of popular sizes and use them instead | ||
// @ts-ignore | ||
whizzzkid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
iconDefinition = await rasterIconDefinition(iconPath) | ||
await browser.action.setIcon(iconDefinition) | ||
} | ||
|
@@ -537,13 +549,15 @@ export default async function init (windowedContext = false) { | |
if (state.automaticMode && state.localGwAvailable) { | ||
if (oldPeerCount === offlinePeerCount && newPeerCount > offlinePeerCount && !state.redirect) { | ||
await browser.storage.local.set({ useCustomGateway: true }) | ||
// @ts-ignore | ||
whizzzkid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
reloadIpfsClientOfflinePages(browser, ipfs, state) | ||
} else if (newPeerCount === offlinePeerCount && state.redirect) { | ||
await browser.storage.local.set({ useCustomGateway: false }) | ||
} | ||
} | ||
} | ||
|
||
// @ts-ignore | ||
whizzzkid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
async function onStorageChange (changes, area) { | ||
let shouldReloadExtension = false | ||
let shouldRestartIpfsClient = false | ||
|
@@ -634,6 +648,7 @@ export default async function init (windowedContext = false) { | |
await destroyIpfsClient(browser) | ||
} catch (err) { | ||
console.error('[ipfs-companion] Failed to destroy IPFS client', err) | ||
// @ts-ignore | ||
whizzzkid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
notify('notify_stopIpfsNodeErrorTitle', err.message) | ||
} finally { | ||
ipfs = null | ||
|
@@ -648,6 +663,7 @@ export default async function init (windowedContext = false) { | |
console.error('[ipfs-companion] Failed to init IPFS client', err) | ||
notify( | ||
'notify_startIpfsNodeErrorTitle', | ||
// @ts-ignore | ||
whizzzkid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
err.name === 'ValidationError' ? err.details[0].message : err.message | ||
) | ||
} | ||
|
@@ -715,9 +731,11 @@ export default async function init (windowedContext = false) { | |
return api | ||
} | ||
|
||
// @ts-ignore | ||
whizzzkid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const rasterIconDefinition = pMemoize((svgPath) => { | ||
const pngPath = (size) => { | ||
// point at precomputed PNG file | ||
// @ts-ignore | ||
whizzzkid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const baseName = /\/icons\/(.+)\.svg/.exec(svgPath)[1] | ||
return `/icons/png/${baseName}_${size}.png` | ||
} | ||
|
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the latest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will be fixed in another PR.