Using the scripts onload
and onerror
events is most likely an option here I suppose.
// Set up the onload handler before appending to DOM
tag.onload = () => {
//Check if Google Pay exists
if ('google' in window && window.google.payments && window.google.payments.api) {
loadGooglePay();
} else {
console.error("Where response???");
}
};