bug1472075-bankofamerica.com-ua-change.js (1561B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 /** 8 * Bug 1472075 - Build UA override for Bank of America for OSX & Linux 9 * WebCompat issue #2787 - https://webcompat.com/issues/2787 10 * 11 * BoA is showing a red warning to Linux and macOS users, while accepting 12 * Windows users without warning. From our side, there is no difference here 13 * and we receive a lot of user complains about the warnings, so we spoof 14 * as Firefox on Windows in those cases. 15 */ 16 17 /* globals exportFunction */ 18 19 if (!navigator.platform.includes("Win")) { 20 console.info( 21 "The user agent has been overridden for compatibility reasons. See https://webcompat.com/issues/2787 for details." 22 ); 23 24 const WINDOWS_UA = navigator.userAgent.replace( 25 /\(.*; rv:/i, 26 "(Windows NT 10.0; Win64; x64; rv:" 27 ); 28 29 const nav = Object.getPrototypeOf(navigator.wrappedJSObject); 30 31 const ua = Object.getOwnPropertyDescriptor(nav, "userAgent"); 32 ua.get = exportFunction(() => WINDOWS_UA, window); 33 Object.defineProperty(nav, "userAgent", ua); 34 35 const appVersion = Object.getOwnPropertyDescriptor(nav, "appVersion"); 36 appVersion.get = exportFunction(() => "appVersion", window); 37 Object.defineProperty(nav, "appVersion", appVersion); 38 39 const platform = Object.getOwnPropertyDescriptor(nav, "platform"); 40 platform.get = exportFunction(() => "Win64", window); 41 Object.defineProperty(nav, "platform", platform); 42 }