-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (33 loc) · 966 Bytes
/
index.js
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
let url = null;
let popup = "";
let interval = null;
window.addEventListener("load", () => {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
url = new URL(urlParams.get('href'));
})
const polling = () => {
interval = setInterval(() => {
console.log("polling HANDSHAKE-SYN...");
popup.postMessage("HANDSHAKE-SYN", url.href);
}, 500);
}
document.getElementById("opener").addEventListener("click", () => {
popup = window.open(url.href);
polling();
});
window.addEventListener(
"message",
(event) => {
console.log(event.origin, event.data);
if(event.origin === url.origin) {
if (event.data === "HANDSHAKE-ACK") {
clearInterval(interval);
}
document
.getElementById("logger")
.append(`<p>${JSON.stringify(event.data)}</p>`);
}
},
false
);