bug1950282-f1tv.formula1.com-unblock-firefox.js (3449B)
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 1950282 - UA spoof for f1tv.formula1.com 9 * 10 * This site is deliberately blocking Firefox, possibly due to bug 1992579. 11 */ 12 13 /* globals cloneInto, exportFunction */ 14 15 console.info( 16 "The window environment is being altered for compatibility reasons. If you're a web developer working on this site, please get in touch with developer-outreach@mozilla.com. See https://bugzilla.mozilla.org/show_bug.cgi?id=1950282 for details." 17 ); 18 19 delete window.wrappedJSObject.InstallTrigger; 20 delete window.wrappedJSObject.mozInnerScreenX; 21 delete window.wrappedJSObject.mozInnerScreenY; 22 delete window.wrappedJSObject.MozConsentBanner; 23 24 const nav = Object.getPrototypeOf(navigator.wrappedJSObject); 25 const vendor = Object.getOwnPropertyDescriptor(nav, "vendor"); 26 vendor.get = exportFunction(() => "Google Inc.", window); 27 Object.defineProperty(nav, "vendor", vendor); 28 29 const css = CSS.wrappedJSObject; 30 const supports = Object.getOwnPropertyDescriptor(css, "supports"); 31 const oldSupports = supports.value; 32 supports.value = exportFunction(function (query) { 33 if (query.includes("moz-")) { 34 return false; 35 } 36 return oldSupports.call(this, query); 37 }, window); 38 Object.defineProperty(css, "supports", supports); 39 40 function generateTimeStamp(base, factor = 10) { 41 if (base) { 42 // increase another timestamp by a little 43 return (base + Math.random() * factor).toString().substr(0, 14); 44 } 45 const r = Math.random().toString(); 46 const d10 = `1${r.substr(5, 9)}`; 47 const d3 = r.substr(2, 3); 48 return parseFloat(`${d10}.${d3}`); 49 } 50 51 const startLoadTime = generateTimeStamp(); 52 const commitLoadTime = generateTimeStamp(startLoadTime); 53 const firstPaintTime = generateTimeStamp(commitLoadTime); 54 const finishDocumentLoadTime = generateTimeStamp(firstPaintTime); 55 const finishLoadTime = generateTimeStamp(finishDocumentLoadTime); 56 57 const csi = cloneInto( 58 { 59 onloadT: parseInt(finishDocumentLoadTime * 100), 60 pageT: generateTimeStamp().toString().substr(-11), 61 startE: parseInt(parseFloat(startLoadTime * 100)), 62 tran: 10 + parseInt(4 + Math.random() * 4), 63 }, 64 window 65 ); 66 67 const loadTimes = cloneInto( 68 { 69 commitLoadTime, 70 connectionInfo: "h3", 71 finishDocumentLoadTime, 72 finishLoadTime, 73 firstPaintAfterLoadTime: 0, 74 firstPaintTime, 75 navigationType: "Other", 76 npnNegotiatedProtocol: "h3", 77 requestTime: startLoadTime, 78 startLoadTime, 79 wasAlternateProtocolAvailable: false, 80 wasFetchedViaSpdy: true, 81 wasNpnNegotiated: true, 82 }, 83 window 84 ); 85 86 window.wrappedJSObject.chrome = cloneInto( 87 { 88 app: { 89 InstallState: { 90 DISABLED: "disabled", 91 INSTALLED: "installed", 92 NOT_INSTALLED: "not_installed", 93 }, 94 RunningState: { 95 CANNOT_RUN: "cannot_run", 96 READY_TO_RUN: "ready_to_run", 97 RUNNING: "running", 98 }, 99 getDetails() { 100 return null; 101 }, 102 getIsInstalled() { 103 return false; 104 }, 105 installState() { 106 return undefined; 107 }, 108 isInstalled: false, 109 runningState() { 110 return window.chrome.app.InstallState.NOT_INSTALLED; 111 }, 112 }, 113 csi() { 114 return csi; 115 }, 116 loadTimes() { 117 return loadTimes; 118 }, 119 }, 120 window, 121 { cloneFunctions: true } 122 );