diff --git a/testing/web-platform/tests/secure-payment-confirmation/utils.sub.js b/testing/web-platform/tests/secure-payment-confirmation/utils.sub.js index 705de30bbd6f8..904f3d8d64812 100644 --- a/testing/web-platform/tests/secure-payment-confirmation/utils.sub.js +++ b/testing/web-platform/tests/secure-payment-confirmation/utils.sub.js @@ -64,7 +64,21 @@ async function createCredentialForAltDomain() { frame.src = 'https://{{hosts[alt][]}}:{{ports[https][0]}}' + '/secure-payment-confirmation/resources/iframe-enroll.html'; - return new Promise(resolve => { + // Wait for the iframe to load. + const readyPromise = new Promise(resolve => { + window.addEventListener('message', function handler(evt) { + if (evt.source === frame.contentWindow && evt.data.type == 'loaded') { + window.removeEventListener('message', handler); + + resolve(evt.data); + } + }); + }); + document.body.appendChild(frame); + await readyPromise; + + // Setup the result promise, and then trigger credential creation. + const resultPromise = new Promise(resolve => { window.addEventListener('message', function handler(evt) { if (evt.source === frame.contentWindow) { document.body.removeChild(frame); @@ -73,8 +87,9 @@ async function createCredentialForAltDomain() { resolve(evt.data); } }); - document.body.appendChild(frame); }); + frame.contentWindow.postMessage({ userActivation: true }, '*'); + return resultPromise; } function arrayBufferToString(buffer) {