diff options
Diffstat (limited to 'browser/extensions/webcompat/injections/js')
28 files changed, 953 insertions, 0 deletions
diff --git a/browser/extensions/webcompat/injections/js/bug0000000-testbed-js-injection.js b/browser/extensions/webcompat/injections/js/bug0000000-testbed-js-injection.js new file mode 100644 index 0000000000..7a192d6c41 --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug0000000-testbed-js-injection.js @@ -0,0 +1,15 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/* globals exportFunction */ + +Object.defineProperty(window.wrappedJSObject, "isTestFeatureSupported", { + get: exportFunction(function () { + return true; + }, window), + + set: exportFunction(function () {}, window), +}); diff --git a/browser/extensions/webcompat/injections/js/bug1448747-fastclick-shim.js b/browser/extensions/webcompat/injections/js/bug1448747-fastclick-shim.js new file mode 100644 index 0000000000..7a8e85f538 --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1448747-fastclick-shim.js @@ -0,0 +1,35 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1448747 - Neutralize FastClick + * + * The patch is applied on sites using FastClick library + * to make sure `FastClick.notNeeded` returns `true`. + * This allows to disable FastClick and fix various breakage caused + * by the library (mainly non-functioning drop-down lists). + */ + +/* globals exportFunction */ + +(function () { + const proto = CSS2Properties.prototype.wrappedJSObject; + const descriptor = Object.getOwnPropertyDescriptor(proto, "touchAction"); + const { get } = descriptor; + + descriptor.get = exportFunction(function () { + try { + throw Error(); + } catch (e) { + if (e.stack?.includes("notNeeded")) { + return "none"; + } + } + return get.call(this); + }, window); + + Object.defineProperty(proto, "touchAction", descriptor); +})(); diff --git a/browser/extensions/webcompat/injections/js/bug1452707-window.controllers-shim-ib.absa.co.za.js b/browser/extensions/webcompat/injections/js/bug1452707-window.controllers-shim-ib.absa.co.za.js new file mode 100644 index 0000000000..40e17b4a36 --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1452707-window.controllers-shim-ib.absa.co.za.js @@ -0,0 +1,33 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1452707 - Build site patch for ib.absa.co.za + * WebCompat issue #16401 - https://webcompat.com/issues/16401 + * + * The online banking at ib.absa.co.za detect if window.controllers is a + * non-falsy value to detect if the current browser is Firefox or something + * else. In bug 1448045, this shim has been disabled for Firefox Nightly 61+, + * which breaks the UA detection on this site and results in a "Browser + * unsuppored" error message. + * + * This site patch simply sets window.controllers to a string, resulting in + * their check to work again. + */ + +/* globals exportFunction */ + +console.info( + "window.controllers has been shimmed for compatibility reasons. See https://webcompat.com/issues/16401 for details." +); + +Object.defineProperty(window.wrappedJSObject, "controllers", { + get: exportFunction(function () { + return true; + }, window), + + set: exportFunction(function () {}, window), +}); diff --git a/browser/extensions/webcompat/injections/js/bug1457335-histography.io-ua-change.js b/browser/extensions/webcompat/injections/js/bug1457335-histography.io-ua-change.js new file mode 100644 index 0000000000..06085acc5a --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1457335-histography.io-ua-change.js @@ -0,0 +1,38 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1457335 - histography.io - Override UA & navigator.vendor + * WebCompat issue #1804 - https://webcompat.com/issues/1804 + * + * This site is using a strict matching of navigator.userAgent and + * navigator.vendor to allow access for Safari or Chrome. Here, we set the + * values appropriately so we get recognized as Chrome. + */ + +/* globals exportFunction */ + +console.info( + "The user agent has been overridden for compatibility reasons. See https://webcompat.com/issues/1804 for details." +); + +const CHROME_UA = navigator.userAgent + " Chrome for WebCompat"; + +Object.defineProperty(window.navigator.wrappedJSObject, "userAgent", { + get: exportFunction(function () { + return CHROME_UA; + }, window), + + set: exportFunction(function () {}, window), +}); + +Object.defineProperty(window.navigator.wrappedJSObject, "vendor", { + get: exportFunction(function () { + return "Google Inc."; + }, window), + + set: exportFunction(function () {}, window), +}); diff --git a/browser/extensions/webcompat/injections/js/bug1472075-bankofamerica.com-ua-change.js b/browser/extensions/webcompat/injections/js/bug1472075-bankofamerica.com-ua-change.js new file mode 100644 index 0000000000..5aa72e75ae --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1472075-bankofamerica.com-ua-change.js @@ -0,0 +1,52 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1472075 - Build UA override for Bank of America for OSX & Linux + * WebCompat issue #2787 - https://webcompat.com/issues/2787 + * + * BoA is showing a red warning to Linux and macOS users, while accepting + * Windows users without warning. From our side, there is no difference here + * and we receive a lot of user complains about the warnings, so we spoof + * as Firefox on Windows in those cases. + */ + +/* globals exportFunction */ + +if (!navigator.platform.includes("Win")) { + console.info( + "The user agent has been overridden for compatibility reasons. See https://webcompat.com/issues/2787 for details." + ); + + const WINDOWS_UA = navigator.userAgent.replace( + /\(.*; rv:/i, + "(Windows NT 10.0; Win64; x64; rv:" + ); + + Object.defineProperty(window.navigator.wrappedJSObject, "userAgent", { + get: exportFunction(function () { + return WINDOWS_UA; + }, window), + + set: exportFunction(function () {}, window), + }); + + Object.defineProperty(window.navigator.wrappedJSObject, "appVersion", { + get: exportFunction(function () { + return "appVersion"; + }, window), + + set: exportFunction(function () {}, window), + }); + + Object.defineProperty(window.navigator.wrappedJSObject, "platform", { + get: exportFunction(function () { + return "Win64"; + }, window), + + set: exportFunction(function () {}, window), + }); +} diff --git a/browser/extensions/webcompat/injections/js/bug1579159-m.tailieu.vn-pdfjs-worker-disable.js b/browser/extensions/webcompat/injections/js/bug1579159-m.tailieu.vn-pdfjs-worker-disable.js new file mode 100644 index 0000000000..5c757466c6 --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1579159-m.tailieu.vn-pdfjs-worker-disable.js @@ -0,0 +1,32 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * m.tailieu.vn - Override PDFJS.disableWorker to be true + * WebCompat issue #39057 - https://webcompat.com/issues/39057 + * + * Custom viewer built with PDF.js is not working in Firefox for Android + * Disabling worker to match Chrome behavior fixes the issue + */ + +/* globals exportFunction */ + +console.info( + "window.PDFJS.disableWorker has been set to true for compatibility reasons. See https://webcompat.com/issues/39057 for details." +); + +let globals = {}; + +Object.defineProperty(window.wrappedJSObject, "PDFJS", { + get: exportFunction(function () { + return globals; + }, window), + + set: exportFunction(function (value = {}) { + globals = value; + globals.disableWorker = true; + }, window), +}); diff --git a/browser/extensions/webcompat/injections/js/bug1605611-maps.google.com-directions-time.js b/browser/extensions/webcompat/injections/js/bug1605611-maps.google.com-directions-time.js new file mode 100644 index 0000000000..a068e8dcd5 --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1605611-maps.google.com-directions-time.js @@ -0,0 +1,38 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1605611 - Cannot change Departure/arrival dates in Google Maps on Android + * + * This patch re-enables the disabled "Leave now" button. + * + * See https://bugzilla.mozilla.org/show_bug.cgi?id=1800498 and + * https://bugzilla.mozilla.org/show_bug.cgi?id=1605611 for details. + */ + +const selector = + ".ml-directions-searchbox-parent [aria-haspopup=dialog][disabled=true]"; + +document.addEventListener("DOMContentLoaded", () => { + // In case the element appeared before the MutationObserver was activated. + for (const elem of document.querySelectorAll(selector)) { + elem.disabled = false; + } + // Start watching for the insertion of the "Leave now" button. + const moOptions = { + attributeFilter: ["disabled"], + attributes: true, + subtree: true, + }; + const mo = new MutationObserver(function (records) { + for (const { target } of records) { + if (target.matches(selector)) { + target.disabled = false; + } + } + }); + mo.observe(document.body, moOptions); +}); diff --git a/browser/extensions/webcompat/injections/js/bug1631811-datastudio.google.com-indexedDB.js b/browser/extensions/webcompat/injections/js/bug1631811-datastudio.google.com-indexedDB.js new file mode 100644 index 0000000000..fb9be74039 --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1631811-datastudio.google.com-indexedDB.js @@ -0,0 +1,22 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1631811 - disable indexedDB for datastudio.google.com iframes + * + * Indexed DB is disabled already for these iframes due to cookie blocking. + * This intervention changes the functionality from throwing a SecurityError + * when indexedDB is accessed to removing it from the window object + */ + +console.info( + "window.indexedDB has been overwritten for compatibility reasons. See https://bugzilla.mozilla.org/show_bug.cgi?id=1631811 for details." +); + +Object.defineProperty(window.wrappedJSObject, "indexedDB", { + get: undefined, + set: undefined, +}); diff --git a/browser/extensions/webcompat/injections/js/bug1722955-frontgate.com-ua-override.js b/browser/extensions/webcompat/injections/js/bug1722955-frontgate.com-ua-override.js new file mode 100644 index 0000000000..577a55450a --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1722955-frontgate.com-ua-override.js @@ -0,0 +1,21 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/* + * Bug 1722955 - Add UA override for frontgate.com + * Webcompat issue #36277 - https://github.com/webcompat/web-bugs/issues/36277 + * + * The website is sending the desktop version to Firefox on mobile devices + * based on UA sniffing. Spoofing as Chrome fixes this. + */ + +/* globals exportFunction, UAHelpers */ + +console.info( + "The user agent has been overridden for compatibility reasons. See https://webcompat.com/issues/36277 for details." +); + +UAHelpers.overrideWithDeviceAppropriateChromeUA(); diff --git a/browser/extensions/webcompat/injections/js/bug1724764-window-print.js b/browser/extensions/webcompat/injections/js/bug1724764-window-print.js new file mode 100644 index 0000000000..20e9ecf22d --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1724764-window-print.js @@ -0,0 +1,28 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Generic window.print shim + * + * Issues related to an error caused by missing window.print() method on Android. + * Adding print to the window object allows to unbreak the sites. + */ + +/* globals exportFunction */ + +if (typeof window.print === "undefined") { + console.info( + "window.print has been shimmed for compatibility reasons. See https://bugzilla.mozilla.org/show_bug.cgi?id=1659818 for details." + ); + + Object.defineProperty(window.wrappedJSObject, "print", { + get: exportFunction(function () { + return true; + }, window), + + set: exportFunction(function () {}, window), + }); +} diff --git a/browser/extensions/webcompat/injections/js/bug1724868-news.yahoo.co.jp-ua-override.js b/browser/extensions/webcompat/injections/js/bug1724868-news.yahoo.co.jp-ua-override.js new file mode 100644 index 0000000000..ab7b76c799 --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1724868-news.yahoo.co.jp-ua-override.js @@ -0,0 +1,29 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1724868 - news.yahoo.co.jp - Override UA + * WebCompat issue #82605 - https://webcompat.com/issues/82605 + * + * Yahoo Japan news doesn't allow playing video in Firefox on Android + * as they don't have it in their support matrix. They check UA override twice + * and display different ui with the same error. Changing UA to Chrome via + * content script allows playing the videos. + */ + +/* globals exportFunction */ + +console.info( + "The user agent has been overridden for compatibility reasons. See https://webcompat.com/issues/82605 for details." +); + +Object.defineProperty(window.navigator.wrappedJSObject, "userAgent", { + get: exportFunction(function () { + return "Mozilla/5.0 (Linux; Android 11; Pixel 4a) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Mobile Safari/537.36"; + }, window), + + set: exportFunction(function () {}, window), +}); diff --git a/browser/extensions/webcompat/injections/js/bug1731825-office365-email-handling-prompt-autohide.js b/browser/extensions/webcompat/injections/js/bug1731825-office365-email-handling-prompt-autohide.js new file mode 100644 index 0000000000..d1823aec74 --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1731825-office365-email-handling-prompt-autohide.js @@ -0,0 +1,36 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1731825 - Office 365 email handling prompt autohide + * + * This site patch prevents the notification bar on Office 365 + * apps from popping up on each page-load, offering to handle + * email with Outlook. + */ + +/* globals exportFunction */ + +const warning = + "Office 365 Outlook email handling prompt has been hidden. See https://bugzilla.mozilla.org/show_bug.cgi?id=1731825 for details."; + +const localStorageKey = "mailProtocolHandlerAlreadyOffered"; + +const nav = navigator.wrappedJSObject; +const { registerProtocolHandler } = nav; +const { localStorage } = window.wrappedJSObject; + +Object.defineProperty(navigator.wrappedJSObject, "registerProtocolHandler", { + value: exportFunction(function (scheme, url, title) { + if (localStorage.getItem(localStorageKey)) { + console.info(warning); + return undefined; + } + registerProtocolHandler.call(nav, scheme, url, title); + localStorage.setItem(localStorageKey, true); + return undefined; + }, window), +}); diff --git a/browser/extensions/webcompat/injections/js/bug1739489-draftjs-beforeinput.js b/browser/extensions/webcompat/injections/js/bug1739489-draftjs-beforeinput.js new file mode 100644 index 0000000000..5ae55ec6f3 --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1739489-draftjs-beforeinput.js @@ -0,0 +1,116 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1739489 - Entering an emoji using the MacOS IME "crashes" Draft.js editors. + */ + +/* globals exportFunction */ + +console.info( + "textInput event has been remapped to beforeinput for compatibility reasons. See https://bugzilla.mozilla.org/show_bug.cgi?id=1739489 for details." +); + +window.wrappedJSObject.TextEvent = window.wrappedJSObject.InputEvent; + +const { CustomEvent, Event, EventTarget } = window.wrappedJSObject; +var Remapped = [ + [CustomEvent, "constructor"], + [Event, "constructor"], + [Event, "initEvent"], + [EventTarget, "addEventListener"], + [EventTarget, "removeEventListener"], +]; + +for (const [obj, name] of Remapped) { + const { prototype } = obj; + const orig = prototype[name]; + Object.defineProperty(prototype, name, { + value: exportFunction(function (type, b, c, d) { + if (type?.toLowerCase() === "textinput") { + type = "beforeinput"; + } + return orig.call(this, type, b, c, d); + }, window), + }); +} + +if (location.host === "www.reddit.com") { + (function () { + const EditorCSS = ".public-DraftEditor-content[contenteditable=true]"; + let obsEditor, obsStart, obsText, obsKey, observer; + const obsConfig = { characterData: true, childList: true, subtree: true }; + const obsHandler = () => { + observer.disconnect(); + const finalTextNode = obsEditor.querySelector( + `[data-offset-key="${obsKey}"] [data-text='true']` + ).firstChild; + const end = obsStart + obsText.length; + window + .getSelection() + .setBaseAndExtent(finalTextNode, end, finalTextNode, end); + }; + observer = new MutationObserver(obsHandler); + + document.documentElement.addEventListener( + "beforeinput", + e => { + if (e.inputType != "insertFromPaste") { + return; + } + const { target } = e; + obsEditor = target.closest(EditorCSS); + if (!obsEditor) { + return; + } + const items = e?.dataTransfer.items; + for (let item of items) { + if (item.type === "text/plain") { + e.preventDefault(); + item.getAsString(text => { + obsText = text; + + // find the editor-managed <span> which contains the text node the + // cursor starts on, and the cursor's location (or the selection start) + const sel = window.getSelection(); + obsStart = sel.anchorOffset; + let anchor = sel.anchorNode; + if (!anchor.closest) { + anchor = anchor.parentElement; + } + anchor = anchor.closest("[data-offset-key]"); + obsKey = anchor.getAttribute("data-offset-key"); + + // set us up to wait for the editor to either update or replace the + // <span> with that key (the one containing the text to be changed). + // we will then make sure the cursor is after the pasted text, as if + // the editor recreates the node, the cursor position is lost + observer.observe(obsEditor, obsConfig); + + // force the editor to "paste". sending paste or other events will not + // work, nor using execCommand (adding HTML will screw up the DOM that + // the editor expects, and adding plain text will make it ignore newlines). + target.dispatchEvent( + new InputEvent("beforeinput", { + inputType: "insertText", + data: text, + bubbles: true, + cancelable: true, + }) + ); + + // blur the editor to force it to update/flush its state, because otherwise + // the paste works, but the editor doesn't show it (until it is re-focused). + obsEditor.blur(); + }); + break; + } + } + }, + true + ); + })(); +} diff --git a/browser/extensions/webcompat/injections/js/bug1769762-tiktok.com-plugins-shim.js b/browser/extensions/webcompat/injections/js/bug1769762-tiktok.com-plugins-shim.js new file mode 100644 index 0000000000..7383a4e567 --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1769762-tiktok.com-plugins-shim.js @@ -0,0 +1,35 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1769762 - Empty out navigator.plugins + * WebCompat issue #103612 - https://webcompat.com/issues/103612 + * + * Certain features of the site are breaking if navigator.plugins array is not empty: + * + * 1. "Likes" on the comments are not saved + * 2. Can't reply to other people's comments + * 3. "Likes" on the videos are not saved + * 4. Can't follow an account (after refreshing "Follow" button is visible again) + * + * (note that the first 2 are still broken if you open devtools even with this intervention) + */ + +/* globals exportFunction */ + +console.info( + "The PluginArray has been overridden for compatibility reasons. See https://bugzilla.mozilla.org/show_bug.cgi?id=1753874 for details." +); + +const pluginsArray = new window.wrappedJSObject.Array(); +Object.setPrototypeOf(pluginsArray, PluginArray.prototype); + +Object.defineProperty(navigator.wrappedJSObject, "plugins", { + get: exportFunction(function () { + return pluginsArray; + }, window), + set: exportFunction(function (val) {}, window), +}); diff --git a/browser/extensions/webcompat/injections/js/bug1774005-installtrigger-shim.js b/browser/extensions/webcompat/injections/js/bug1774005-installtrigger-shim.js new file mode 100644 index 0000000000..ca7ef5b6c5 --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1774005-installtrigger-shim.js @@ -0,0 +1,26 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1774005 - Generic window.InstallTrigger shim + * + * This interventions shims window.InstallTrigger to a string, which evaluates + * as `true` in web developers browser sniffing code. This intervention will + * be applied to multiple domains, see bug 1774005 for more information. + */ + +/* globals exportFunction */ + +console.info( + "The InstallTrigger has been shimmed for compatibility reasons. See https://bugzilla.mozilla.org/show_bug.cgi?id=1774005 for details." +); + +Object.defineProperty(window.wrappedJSObject, "InstallTrigger", { + get: exportFunction(function () { + return "This property has been shimed for Web Compatibility reasons."; + }, window), + set: exportFunction(function (_) {}, window), +}); diff --git a/browser/extensions/webcompat/injections/js/bug1784302-effectiveType-shim.js b/browser/extensions/webcompat/injections/js/bug1784302-effectiveType-shim.js new file mode 100644 index 0000000000..7bde4a7d82 --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1784302-effectiveType-shim.js @@ -0,0 +1,27 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1784302 - Issues due to missing navigator.connection after + * https://bugzilla.mozilla.org/show_bug.cgi?id=1637922 landed. + * Webcompat issue #104838 - https://github.com/webcompat/web-bugs/issues/104838 + */ + +/* globals cloneInto, exportFunction */ + +console.info( + "navigator.connection has been shimmed for compatibility reasons. See https://bugzilla.mozilla.org/show_bug.cgi?id=1756692 for details." +); + +var connection = { + addEventListener: () => {}, + removeEventListener: () => {}, + effectiveType: "4g", +}; + +window.navigator.wrappedJSObject.connection = cloneInto(connection, window, { + cloneFunctions: true, +}); diff --git a/browser/extensions/webcompat/injections/js/bug1795490-www.china-airlines.com-undisable-date-fields-on-mobile.js b/browser/extensions/webcompat/injections/js/bug1795490-www.china-airlines.com-undisable-date-fields-on-mobile.js new file mode 100644 index 0000000000..f3c0e03513 --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1795490-www.china-airlines.com-undisable-date-fields-on-mobile.js @@ -0,0 +1,40 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1795490 - Cannot use date fields on China Airlines mobile page + * + * This patch ensures that the search input never has the [disabled] + * attribute, so that users may tap/click on it to search. + * + * See https://bugzilla.mozilla.org/show_bug.cgi?id=1795490 for details. + */ + +const SELECTOR = `#departureDateMobile[disabled], #returnDateMobile[disabled]`; + +function check(target) { + if (target.nodeName === "INPUT" && target.matches(SELECTOR)) { + target.removeAttribute("disabled"); + return true; + } + return false; +} + +new MutationObserver(mutations => { + for (const { addedNodes, target, attributeName } of mutations) { + if (attributeName === "disabled") { + check(target); + } else { + addedNodes?.forEach(node => { + if (!check(node)) { + node + .querySelectorAll?.(SELECTOR) + ?.forEach(n => n.removeAttribute("disabled")); + } + }); + } + } +}).observe(document, { attributes: true, childList: true, subtree: true }); diff --git a/browser/extensions/webcompat/injections/js/bug1799968-www.samsung.com-appVersion-linux-fix.js b/browser/extensions/webcompat/injections/js/bug1799968-www.samsung.com-appVersion-linux-fix.js new file mode 100644 index 0000000000..941f071e2c --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1799968-www.samsung.com-appVersion-linux-fix.js @@ -0,0 +1,31 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1799968 - Build site patch for www.samsung.com + * WebCompat issue #108993 - https://webcompat.com/issues/108993 + * + * Samsung's Watch pages try to detect the OS via navigator.appVersion, + * but fail with Linux because they expect it to contain the literal + * string "linux", and their JS breaks. + * + * As such this site patch sets appVersion to "5.0 (Linux)", and is + * only meant to be applied on Linux. + */ + +/* globals exportFunction */ + +console.info( + "navigator.appVersion has been shimmed for compatibility reasons. See https://webcompat.com/issues/108993 for details." +); + +Object.defineProperty(navigator.wrappedJSObject, "appVersion", { + get: exportFunction(function () { + return "5.0 (Linux)"; + }, window), + + set: exportFunction(function () {}, window), +}); diff --git a/browser/extensions/webcompat/injections/js/bug1799980-healow.com-infinite-loop-fix.js b/browser/extensions/webcompat/injections/js/bug1799980-healow.com-infinite-loop-fix.js new file mode 100644 index 0000000000..191e97dec1 --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1799980-healow.com-infinite-loop-fix.js @@ -0,0 +1,37 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1799980 - Healow gets stuck in an infinite loop while pages load + * + * This patch keeps Healow's localization scripts from getting stuck in + * an infinite loop while their pages are loading. + * + * This happens because they use synchronous XMLHttpRequests to fetch a + * JSON file with their localized text on the first call to their i18n + * function, and then force subsequent calls to wait for it by waiting + * in an infinite loop. + * + * But since they're in an infinite loop, the code after the syncXHR will + * never be able to run, so this ultimately triggers a slow script warning. + * + * We can improve this by just preventing the infinite loop from happening, + * though since they disable caching on their JSON files it means that more + * XHRs may happen. But since those files are small, this seems like a + * reasonable compromise until they migrate to a better i18n solution. + * + * See https://bugzilla.mozilla.org/show_bug.cgi?id=1799980 for details. + */ + +/* globals exportFunction */ + +Object.defineProperty(window.wrappedJSObject, "ajaxRequestProcessing", { + get: exportFunction(function () { + return false; + }, window), + + set: exportFunction(function () {}, window), +}); diff --git a/browser/extensions/webcompat/injections/js/bug1818818-fastclick-legacy-shim.js b/browser/extensions/webcompat/injections/js/bug1818818-fastclick-legacy-shim.js new file mode 100644 index 0000000000..91f1c1a19a --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1818818-fastclick-legacy-shim.js @@ -0,0 +1,24 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1818818 - Neutralize FastClick + * + * The patch is applied on sites using older version of FastClick library. + * This allows to disable FastClick and fix various breakage caused + * by the library. + */ + +/* globals exportFunction */ + +const proto = CSS2Properties.prototype.wrappedJSObject; +Object.defineProperty(proto, "msTouchAction", { + get: exportFunction(function () { + return "none"; + }, window), + + set: exportFunction(function () {}, window), +}); diff --git a/browser/extensions/webcompat/injections/js/bug1819450-cmbchina.com-ua-change.js b/browser/extensions/webcompat/injections/js/bug1819450-cmbchina.com-ua-change.js new file mode 100644 index 0000000000..bbe76c465f --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1819450-cmbchina.com-ua-change.js @@ -0,0 +1,29 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1819450 - cmbchina.com - Override UA + * + * The site is using UA detection to redirect to + * m.cmbchina.com (mobile version of the site). Adding `SAMSUNG` allows + * to bypass the detection of mobile browser. + */ + +/* globals exportFunction */ + +console.info( + "The user agent has been overridden for compatibility reasons. See https://bugzilla.mozilla.org/show_bug.cgi?id=1081239 for details." +); + +const MODIFIED_UA = navigator.userAgent + " SAMSUNG"; + +Object.defineProperty(window.navigator.wrappedJSObject, "userAgent", { + get: exportFunction(function () { + return MODIFIED_UA; + }, window), + + set: exportFunction(function () {}, window), +}); diff --git a/browser/extensions/webcompat/injections/js/bug1819476-axisbank.com-webkitSpeechRecognition-shim.js b/browser/extensions/webcompat/injections/js/bug1819476-axisbank.com-webkitSpeechRecognition-shim.js new file mode 100644 index 0000000000..a72e938e4f --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1819476-axisbank.com-webkitSpeechRecognition-shim.js @@ -0,0 +1,26 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * axisbank.com - Shim webkitSpeechRecognition + * WebCompat issue #117770 - https://webcompat.com/issues/117770 + * + * The page with bank offerings is not loading options due to the + * site relying on webkitSpeechRecognition, which is undefined in Firefox. + * Shimming it to `class {}` makes the pages work. + */ + +/* globals exportFunction */ + +console.info( + "webkitSpeechRecognition was shimmed for compatibility reasons. See https://webcompat.com/issues/117770 for details." +); + +Object.defineProperty(window.wrappedJSObject, "webkitSpeechRecognition", { + value: exportFunction(function () { + return class {}; + }, window), +}); diff --git a/browser/extensions/webcompat/injections/js/bug1819678-cnki.net-undisable-search-field.js b/browser/extensions/webcompat/injections/js/bug1819678-cnki.net-undisable-search-field.js new file mode 100644 index 0000000000..c230feb43d --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1819678-cnki.net-undisable-search-field.js @@ -0,0 +1,45 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1819678 - cnki.net - Cannot use search field + * WebCompat issue #115777 - https://webcompat.com/issues/115777 + * + * This patch ensures that the search input never has the [disabled] + * attribute, so that users may tap/click on it to search. + * + * See https://bugzilla.mozilla.org/show_bug.cgi?id=1819678 for details. + */ + +console.info( + "search input disabled attribute was removed for compatibility reasons. See https://webcompat.com/issues/115777 for details." +); + +const SELECTOR = `.searchimg[disabled]`; + +function check(target) { + if (target.nodeName === "INPUT" && target.matches(SELECTOR)) { + target.removeAttribute("disabled"); + return true; + } + return false; +} + +new MutationObserver(mutations => { + for (const { addedNodes, target, attributeName } of mutations) { + if (attributeName === "disabled") { + check(target); + } else { + addedNodes?.forEach(node => { + if (!check(node)) { + node + .querySelectorAll?.(SELECTOR) + ?.forEach(n => n.removeAttribute("disabled")); + } + }); + } + } +}).observe(document, { attributes: true, childList: true, subtree: true }); diff --git a/browser/extensions/webcompat/injections/js/bug1819678-free4talk.com-window-chrome-shim.js b/browser/extensions/webcompat/injections/js/bug1819678-free4talk.com-window-chrome-shim.js new file mode 100644 index 0000000000..6e6b5823cb --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1819678-free4talk.com-window-chrome-shim.js @@ -0,0 +1,25 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1827678 - UA spoof for www.free4talk.com + * + * This site is checking for window.chrome, so let's spoof that. + */ + +/* globals exportFunction */ + +console.info( + "window.chrome has been shimmed for compatibility reasons. See https://github.com/webcompat/web-bugs/issues/77727 for details." +); + +Object.defineProperty(window.wrappedJSObject, "chrome", { + get: exportFunction(function () { + return true; + }, window), + + set: exportFunction(function () {}, window), +}); diff --git a/browser/extensions/webcompat/injections/js/bug1830776-blueshieldca.com-unsupported.js b/browser/extensions/webcompat/injections/js/bug1830776-blueshieldca.com-unsupported.js new file mode 100644 index 0000000000..2b1eb11baf --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1830776-blueshieldca.com-unsupported.js @@ -0,0 +1,24 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1830776 - blueshieldca.com + * WebCompat issue #112630 - https://webcompat.com/issues/112630 + * + * The site is showing unsupported message in Firefox. + * They're also checking for "browserCollapsed" item in sessionStorage + * before showing the message, to only show it once. Adding this + * item to sessionStorage will make sure the message is not shown + * on the initial load. + */ + +console.info( + "browserCollapsed in sessionStorage has been shimmed for compatibility reasons. See https://bugzilla.mozilla.org/show_bug.cgi?id=1830776 for details." +); + +if (!sessionStorage.getItem("browserCollapsed")) { + sessionStorage.setItem("browserCollapsed", "true"); +} diff --git a/browser/extensions/webcompat/injections/js/bug1831007-nintendo-window-OnetrustActiveGroups.js b/browser/extensions/webcompat/injections/js/bug1831007-nintendo-window-OnetrustActiveGroups.js new file mode 100644 index 0000000000..433c416770 --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1831007-nintendo-window-OnetrustActiveGroups.js @@ -0,0 +1,27 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1831007 - Shim window.OnetrustActiveGroups for Nintendo sites + * + * Nintendo relies on `window.OnetrustActiveGroups` being defined. If it's not, + * users may have intermittent issues signing into their account, as they're + * then trying to call `.split()` on `undefined`. + * + * This intervention sets a default value (an empty string), but still allows + * the value to be overwritten at any time. + */ + +/* globals exportFunction */ + +console.info( + "The window.OnetrustActiveGroups property has been shimmed for compatibility reasons. See https://bugzilla.mozilla.org/show_bug.cgi?id=1831007 for details." +); + +Object.defineProperty(window.wrappedJSObject, "OnetrustActiveGroups", { + value: "", + writable: true, +}); diff --git a/browser/extensions/webcompat/injections/js/bug1836157-thai-masszazs-niceScroll-disable.js b/browser/extensions/webcompat/injections/js/bug1836157-thai-masszazs-niceScroll-disable.js new file mode 100644 index 0000000000..719267748b --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1836157-thai-masszazs-niceScroll-disable.js @@ -0,0 +1,23 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + * Bug 1836157 - Shim navigator.platform on www.thai-massaszs.net/en/ + * + * This page adds niceScroll on Android, which breaks scrolling and + * zooming on Firefox. Adding ` Mac` to `navigator.platform` makes + * the page avoid adding niceScroll entirely, unbreaking the page. + */ + +var plat = navigator.platform; +if (!plat.includes("Mac")) { + console.info( + "The navigator.platform property has been shimmed to include 'Mac' for compatibility reasons. See https://bugzilla.mozilla.org/show_bug.cgi?id=1836157 for details." + ); + + Object.defineProperty(navigator.__proto__.wrappedJSObject, "platform", { + value: plat + " Mac", + writable: true, + }); +} diff --git a/browser/extensions/webcompat/injections/js/bug1842437-www.youtube.com-performance-now-precision.js b/browser/extensions/webcompat/injections/js/bug1842437-www.youtube.com-performance-now-precision.js new file mode 100644 index 0000000000..2d328de108 --- /dev/null +++ b/browser/extensions/webcompat/injections/js/bug1842437-www.youtube.com-performance-now-precision.js @@ -0,0 +1,39 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * Bug 1842437 - When attempting to go back on youtube.com, the content remains the same + * + * If consecutive session history entries had history.state.entryTime set to same value, + * back button doesn't work as expected. The entryTime value is coming from performance.now() + * and modifying its return value slightly to make sure two close consecutive calls don't + * get the same result helped with resolving the issue. + */ + +/* globals exportFunction */ + +console.info( + "performance.now precision has been modified for compatibility reasons. See https://bugzilla.mozilla.org/show_bug.cgi?id=1756970 for details." +); + +const origPerf = performance.wrappedJSObject; +const origNow = origPerf.now; + +let counter = 0; +let previousVal = 0; + +Object.defineProperty(window.performance.wrappedJSObject, "now", { + value: exportFunction(function () { + let originalVal = origNow.call(origPerf); + if (originalVal === previousVal) { + originalVal += 0.00000003 * ++counter; + } else { + previousVal = originalVal; + counter = 0; + } + return originalVal; + }, window), +}); |