zendesk-asana-support.js (1543B)
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 1774567 - Zendesk Asana Support 9 * 10 * The Zendesk Asana support app requires storage access to the Asana Zendesk 11 * integration domain. This shim intercepts clicks on the Zendesk tickets on the 12 * Zendesk view page and requests storage access for the Asana integration 13 * domain. 14 */ 15 16 console.warn( 17 `When interacting with tickets on Zendesk, Firefox calls the Storage Access API on behalf of the site. See https://bugzilla.mozilla.org/show_bug.cgi?id=1949491 for details.` 18 ); 19 20 const STORAGE_ACCESS_ORIGIN = "https://zendesk.integrations.asana.plus"; 21 22 document.documentElement.addEventListener( 23 "click", 24 e => { 25 const { target, isTrusted } = e; 26 if (!isTrusted) { 27 return; 28 } 29 30 // Find the click event on the ticket link. 31 const button = target.closest("a[href*='tickets/']"); 32 if (!button) { 33 return; 34 } 35 36 console.warn( 37 "Calling the Storage Access API on behalf of " + STORAGE_ACCESS_ORIGIN 38 ); 39 40 // Disable the button to prevent it from being clicked again. 41 button.disabled = true; 42 e.stopPropagation(); 43 e.preventDefault(); 44 document 45 .requestStorageAccessForOrigin(STORAGE_ACCESS_ORIGIN) 46 .finally(() => { 47 // Re-enable the button and proceed. 48 button.disabled = false; 49 button.click(); 50 }); 51 }, 52 true 53 );