blob: 52482c859f4cfe6ce459e4ae962e1f89a34b8c88 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
let frameCounter = 0;
function populateForm(optionalContentHtml) {
if (!optionalContentHtml)
optionalContentHtml = '';
const frameName = "form-test-target-" + frameCounter++;
document.body.insertAdjacentHTML(
'afterbegin',
`<iframe name="${frameName}"></iframe>` +
`<form action="/common/blank.html" target="` +
`${frameName}">${optionalContentHtml}</form>`);
return document.getElementsByName(frameName)[0].nextSibling;
}
function submitPromise(form, iframe) {
return new Promise((resolve, reject) => {
iframe.onload = () => resolve(iframe.contentWindow.location.search);
iframe.onerror = () => reject(new Error('iframe onerror fired'));
form.submit();
});
}
function loadPromise(iframe) {
return new Promise((resolve, reject) => {
iframe.onload = function() {
// The initial about:blank load event can be fired before the form navigation occurs.
// See https://github.com/whatwg/html/issues/490 for more information.
if (iframe.contentWindow.location == "about:blank") { return; }
resolve();
};
iframe.onerror = () => reject(new Error('iframe onerror fired'));
});
}
function getParamValue(iframe, paramName) {
let params = (new URL(iframe.contentWindow.location)).searchParams;
return params.get(paramName);
}
|