diff --git a/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Paged/RequestBlockingScript.js b/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Paged/RequestBlockingScript.js index 4917f31175dc..4120168041fc 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Paged/RequestBlockingScript.js +++ b/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Paged/RequestBlockingScript.js @@ -60,10 +60,10 @@ window.__firefox__.execute(function($) { return originalFetch.apply(this, arguments) } - const url = new URL(urlString, window.location.href) + const url = new $.URL(urlString, window.location.href) return sendMessage(url).then(blocked => { if (blocked) { - return Promise.reject(new TypeError('Load failed')) + return Promise.reject(new $.TypeError('Load failed')) } else { return originalFetch.apply(this, arguments) } @@ -98,7 +98,7 @@ window.__firefox__.execute(function($) { try { // We do this in a try/catch block to not fail the request in case we can't // create a URL - resourceURL = new URL(this[localURLProp], window.location.href) + resourceURL = new $.URL(this[localURLProp], window.location.href) } catch (error) { // Ignore this error and proceed like a regular request return originalSend.apply(this, arguments) @@ -110,10 +110,10 @@ window.__firefox__.execute(function($) { Object.defineProperties(this, { readyState: { value: 4 } }) - this.dispatchEvent(patchProgressEvent(new ProgressEvent('loadstart'))) - this.dispatchEvent(new Event('readystatechange')) - this.dispatchEvent(patchProgressEvent(new ProgressEvent('error'))) - this.dispatchEvent(patchProgressEvent(new ProgressEvent('loadend'))) + this.dispatchEvent(patchProgressEvent(new $.ProgressEvent('loadstart'))) + this.dispatchEvent(new $.Event('readystatechange')) + this.dispatchEvent(patchProgressEvent(new $.ProgressEvent('error'))) + this.dispatchEvent(patchProgressEvent(new $.ProgressEvent('loadend'))) } else { originalSend.apply(this, arguments) } diff --git a/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Paged/TrackingProtectionStats.js b/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Paged/TrackingProtectionStats.js index c9b344fe1c31..0395786710a3 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Paged/TrackingProtectionStats.js +++ b/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Paged/TrackingProtectionStats.js @@ -18,7 +18,7 @@ window.__firefox__.execute(function($) { let resourceURL = null; try { - resourceURL = new URL(urlString, document.location.href); + resourceURL = new $.URL(urlString, document.location.href); // First party urls or invalid URLs are not blocked if (document.location.host === resourceURL.host) { diff --git a/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Sandboxed/DeAmpScript.js b/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Sandboxed/DeAmpScript.js index fdd406fe8cef..c8b6aef5f45b 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Sandboxed/DeAmpScript.js +++ b/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Sandboxed/DeAmpScript.js @@ -53,7 +53,7 @@ window.__firefox__.execute(function($) { const targetHref = canonicalLinkElm.getAttribute('href'); try { - const destUrl = new URL(targetHref); + const destUrl = new $.URL(targetHref); W.clearInterval(intervalId); if (W.location.href == destUrl.href || !(destUrl.protocol === 'http:' || destUrl.protocol === 'https:')) { diff --git a/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Sandboxed/SelectorsPollerScript.js b/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Sandboxed/SelectorsPollerScript.js index 4a79fb6cf25b..6f346a008766 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Sandboxed/SelectorsPollerScript.js +++ b/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Sandboxed/SelectorsPollerScript.js @@ -65,26 +65,28 @@ window.__firefox__.execute(function($) { const classIdWithoutHtmlOrBody = '[id]:not(html):not(body),[class]:not(html):not(body)' const CC = { - allSelectors: new Set(), - pendingSelectors: { ids: new Set(), classes: new Set() }, - alwaysHiddenSelectors: new Set(), - hiddenSelectors: new Set(), - unhiddenSelectors: new Set(), + allSelectors: new $.Set(), + pendingSelectors: { ids: new $.Set(), classes: new $.Set() }, + alwaysHiddenSelectors: new $.Set(), + hiddenSelectors: new $.Set(), + unhiddenSelectors: new $.Set(), allStyleRules: [], runQueues: [ // All new selectors go in this first run queue - new Set(), + new $.Set(), // Third party matches go in the second and third queues. - new Set(), + new $.Set(), // This is the final run queue. // It's only evaluated for 1p content one more time. - new Set() + new $.Set() ], // URLS - pendingOrigins: new Set(), + pendingOrigins: new $.Set(), // A map of origin strings and their isFirstParty results - urlFirstParty: new Map(), - alreadyKnownFirstPartySubtrees: new WeakSet() + urlFirstParty: new $.Map(), + alreadyKnownFirstPartySubtrees: new $.WeakSet(), + // A list all the selectors that need to be removed from the stylesheet + selectorsToRemove: [] } /** @@ -97,7 +99,7 @@ window.__firefox__.execute(function($) { } const origins = Array.from(CC.pendingOrigins) - CC.pendingOrigins = new Set() + CC.pendingOrigins = new $.Set() const results = await getPartiness(origins) for (const origin of origins) { @@ -129,8 +131,8 @@ window.__firefox__.execute(function($) { const ids = Array.from(CC.pendingSelectors.ids) const classes = Array.from(CC.pendingSelectors.classes) - CC.pendingSelectors.ids = new Set() - CC.pendingSelectors.classes = new Set() + CC.pendingSelectors.ids = new $.Set() + CC.pendingSelectors.classes = new $.Set() let hasChanges = false const results = await sendSelectors(ids, classes) @@ -322,7 +324,7 @@ window.__firefox__.execute(function($) { selectorsPollingIntervalId = undefined } - const observer = new MutationObserver(onMutations) + const observer = new $.MutationObserver(onMutations) const observerConfig = { subtree: true, @@ -388,7 +390,7 @@ window.__firefox__.execute(function($) { */ const extractOriginFromURLString = (urlString) => { try { - const url = new URL(urlString, window.location.toString()) + const url = new $.URL(urlString, window.location.toString()) return url.origin } catch (error) { console.error(error) @@ -847,7 +849,7 @@ window.__firefox__.execute(function($) { * @returns A list of unhidden selectors */ const unhideSelectorsMatchingElementsAndTheirParents = (nodes) => { - const selectorsUnHidden = new Set() + const selectorsUnHidden = new $.Set() for (const nodeRef of nodes) { const node = nodeRef.deref() @@ -881,7 +883,7 @@ window.__firefox__.execute(function($) { switch (mutation.attributeName) { case 'src': if (extractOriginIfNeeded(changedElm)) { - elementsWithURLs.push(new WeakRef(changedElm)) + elementsWithURLs.push(new $.WeakRef(changedElm)) } break } @@ -889,7 +891,7 @@ window.__firefox__.execute(function($) { for (const node of mutation.addedNodes) { if (!isElement(node)) { continue } if (extractOriginIfNeeded(node)) { - elementsWithURLs.push(new WeakRef(node)) + elementsWithURLs.push(new $.WeakRef(node)) } } } @@ -914,7 +916,7 @@ window.__firefox__.execute(function($) { selectorsPollingIntervalId = undefined } - const observer = new MutationObserver(onURLMutations) + const observer = new $.MutationObserver(onURLMutations) const observerConfig = { subtree: true, @@ -936,7 +938,7 @@ window.__firefox__.execute(function($) { elmWithClassOrId.forEach((node) => { if (extractOriginIfNeeded(node)) { - possibleAdChildNodes.push(new WeakRef(node)) + possibleAdChildNodes.push(new $.WeakRef(node)) } }) diff --git a/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/__firefox__.js b/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/__firefox__.js index 687899c88158..301199e29546 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/__firefox__.js +++ b/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/__firefox__.js @@ -255,6 +255,27 @@ if (!window.__firefox__) { return value; }; + /// Secure URL object + $.URL = window.URL; + /// Secure Event object + $.Event = window.Event; + /// Secure ProgressEvent object + $.ProgressEvent = window.ProgressEvent; + /// Secure MutationObserver object + $.MutationObserver = window.MutationObserver; + /// Secure Map object + $.Map = window.Map; + /// Secure Set object + $.Set = window.Set; + /// Secure TypeError object + $.TypeError = window.TypeError; + /// Secure WeakRef object + $.WeakRef = window.WeakRef; + /// Secure WeakMap object + $.WeakMap = window.WeakMap; + /// Secure WeakSet object + $.WeakSet = window.WeakSet; + /* * Freeze an object and its prototype */