bug1842437-www.youtube.com-performance-now-precision.js (1223B)
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 1842437 - When attempting to go back on youtube.com, the content remains the same 9 * 10 * If consecutive session history entries had history.state.entryTime set to same value, 11 * back button doesn't work as expected. The entryTime value is coming from performance.now() 12 * and modifying its return value slightly to make sure two close consecutive calls don't 13 * get the same result helped with resolving the issue. 14 */ 15 16 /* globals exportFunction */ 17 18 console.info( 19 "performance.now precision has been modified for compatibility reasons. See https://bugzilla.mozilla.org/show_bug.cgi?id=1756970 for details." 20 ); 21 22 let counter = 0; 23 let previousVal = 0; 24 25 const perf = Object.getPrototypeOf(performance.wrappedJSObject); 26 const now = perf.now; 27 perf.now = exportFunction(function () { 28 let originalVal = now.call(this); 29 if (originalVal === previousVal) { 30 originalVal += 0.00000003 * ++counter; 31 } else { 32 previousVal = originalVal; 33 counter = 0; 34 } 35 return originalVal; 36 }, window);