history.js (1583B)
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 1624853 - Shim Storage Access API on history.com 9 * 10 * history.com uses Adobe as a necessary third party to authenticating 11 * with a TV provider. In order to accomodate this, we grant storage access 12 * to the Adobe domain via the Storage Access API when the login or logout 13 * buttons are clicked, then forward the click to continue as normal. 14 */ 15 16 console.warn( 17 `When using oauth, Firefox calls the Storage Access API on behalf of the site. See https://bugzilla.mozilla.org/show_bug.cgi?id=1624853 for details.` 18 ); 19 20 // Third-party origin we need to request storage access for. 21 const STORAGE_ACCESS_ORIGIN = "https://sp.auth.adobe.com"; 22 23 document.documentElement.addEventListener( 24 "click", 25 e => { 26 const { target, isTrusted } = e; 27 if (!isTrusted) { 28 return; 29 } 30 31 const button = target.closest("a"); 32 if (!button) { 33 return; 34 } 35 36 const buttonLink = button.href; 37 if (buttonLink?.startsWith("https://www.history.com/mvpd-auth")) { 38 button.disabled = true; 39 button.style.opacity = 0.5; 40 e.stopPropagation(); 41 e.preventDefault(); 42 document 43 .requestStorageAccessForOrigin(STORAGE_ACCESS_ORIGIN) 44 .then(() => { 45 target.click(); 46 }) 47 .catch(() => { 48 button.disabled = false; 49 button.style.opacity = 1.0; 50 }); 51 } 52 }, 53 true 54 );