I have a button that needs to fetch data on click before calling a third party library which ultimately opens a popup window.
The problem that I have is that it works in Chrome, but fails in Firefox and Safari because the popup window is being blocked by their popup blockers.
Avoid browser popup blockers contains a work-around, however it doesn't work for me because I don't instantiate the popup window myself (the third party library does)
Is there a way to get Firefox and Safari to recognize a click > fetch (promise) as a user initiated action so that it doesn't trigger the popup blocker?
Note: The following snippet is included for readability, but it doesn't behave as expected using the StackOverflow code snippet tool. It is reproducible in the following JSFiddle: https://jsfiddle.net/jwrLgqs3/
function thirdPartyLibraryThatOpensWindow(params) {
window.open(params.url);
}
document.querySelector('button').addEventListener('click', async () => {
const response = await fetch('https://dog.ceo/api/breeds/image/random');
const data = await response.json();
thirdPartyLibraryThatOpensWindow({url: data.message});
});
<button>Promise Button</button>
EDIT: I am using Firefox 70.0.1 on MacOS Mojave (10.14.6)
EDIT: Update to fix up statements that it was working in Safari, it doesn't
EDIT: Works in Opera 64