diff --git a/add-on/src/lib/ipfs-request.js b/add-on/src/lib/ipfs-request.js index f811390df..15ed5cab5 100644 --- a/add-on/src/lib/ipfs-request.js +++ b/add-on/src/lib/ipfs-request.js @@ -10,7 +10,7 @@ import { recoveryPagePath } from './constants.js' import { braveNodeType } from './ipfs-client/brave.js' import { dropSlash, ipfsUri, pathAtHttpGateway, sameGateway } from './ipfs-path.js' import { safeURL } from './options.js' -import { addRuleToDynamicRuleSetGenerator, isLocalHost, supportsBlock } from './redirect-handler/blockOrObserve.js' +import { addRuleToDynamicRuleSetGenerator, isLocalHost, supportsDeclarativeNetRequest } from './redirect-handler/blockOrObserve.js' import { RequestTracker } from './trackers/requestTracker.js' const log = debug('ipfs-companion:request') @@ -488,7 +488,7 @@ export function createRequestModifier (getState, dnslinkResolver, ipfsPathValida async function handleRedirection ({ originUrl, redirectUrl, request }) { if (redirectUrl !== '' && originUrl !== '' && redirectUrl !== originUrl) { resolvedRequestTracker.track(request) - if (supportsBlock()) { + if (!supportsDeclarativeNetRequest()) { return { redirectUrl } } diff --git a/add-on/src/lib/redirect-handler/blockOrObserve.ts b/add-on/src/lib/redirect-handler/blockOrObserve.ts index 3c1c72e6b..486346193 100644 --- a/add-on/src/lib/redirect-handler/blockOrObserve.ts +++ b/add-on/src/lib/redirect-handler/blockOrObserve.ts @@ -46,7 +46,7 @@ export const defaultNSRegexStr = `(${[...DEFAULT_NAMESPACES].join('|')})` // the way sinon ends up stubbing it, it's not directly available in the global scope on import // rather it gets replaced dynamically when the module is imported. Which means, we can't // just check for the existence of the property, we need to call the browser instance at that point. -export const supportsBlock = (): boolean => !(browser.declarativeNetRequest?.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES > 0) +export const supportsDeclarativeNetRequest = (): boolean => browser.declarativeNetRequest?.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES > 0 /** * Sends message to self to notify about change. @@ -55,7 +55,7 @@ export const supportsBlock = (): boolean => !(browser.declarativeNetRequest?.MAX */ async function sendMessageToSelf (msg: messageToSelfType, value?: any): Promise { // this check ensures we don't send messages to ourselves if blocking mode is enabled. - if (!supportsBlock()) { + if (supportsDeclarativeNetRequest()) { const message: messageToSelf = { type: msg, value } // on FF, this call waits for the response from the listener. // on Chrome, this needs a callback. @@ -156,7 +156,7 @@ function constructRegexFilter ({ originUrl, redirectUrl }: IRegexFilter): IFilte // If the browser supports the declarativeNetRequest API, we can block the request. export function getExtraInfoSpec (additionalParams: T[] = []): T[] { - if (supportsBlock()) { + if (!supportsDeclarativeNetRequest()) { return ['blocking' as T, ...additionalParams] } return additionalParams @@ -182,7 +182,7 @@ function validateIfRuleChanged (rule: browser.DeclarativeNetRequest.Rule): boole * Clean up all the rules, when extension is disabled. */ export async function cleanupRules (resetInMemory: boolean = false): Promise { - if (supportsBlock()) { + if (!supportsDeclarativeNetRequest()) { return } const existingRules = await browser.declarativeNetRequest.getDynamicRules() diff --git a/add-on/src/options/page.js b/add-on/src/options/page.js index d8a73f8bc..e7d79e25f 100644 --- a/add-on/src/options/page.js +++ b/add-on/src/options/page.js @@ -2,17 +2,17 @@ /* eslint-env browser, webextensions */ import html from 'choo/html/index.js' -import globalToggleForm from './forms/global-toggle-form.js' -import ipfsNodeForm from './forms/ipfs-node-form.js' -import fileImportForm from './forms/file-import-form.js' -import dnslinkForm from './forms/dnslink-form.js' -import gatewaysForm from './forms/gateways-form.js' +import { supportsDeclarativeNetRequest } from '../lib/redirect-handler/blockOrObserve.js' import apiForm from './forms/api-form.js' +import dnslinkForm from './forms/dnslink-form.js' import experimentsForm from './forms/experiments-form.js' -import telemetryForm from './forms/telemetry-form.js' -import resetForm from './forms/reset-form.js' +import fileImportForm from './forms/file-import-form.js' +import gatewaysForm from './forms/gateways-form.js' +import globalToggleForm from './forms/global-toggle-form.js' +import ipfsNodeForm from './forms/ipfs-node-form.js' import redirectRuleForm from './forms/redirect-rule-form.js' -import { supportsBlock } from '../lib/redirect-handler/blockOrObserve.js' +import resetForm from './forms/reset-form.js' +import telemetryForm from './forms/telemetry-form.js' // Render the options page: // Passed current app `state` from the store and `emit`, a function to create @@ -115,7 +115,7 @@ export default function optionsPage (state, emit) { ${resetForm({ onOptionsReset })} - ${supportsBlock() + ${!supportsDeclarativeNetRequest() ? '' : redirectRuleForm({ redirectRules: state.redirectRules,