-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathclose.html
More file actions
40 lines (37 loc) · 1.05 KB
/
close.html
File metadata and controls
40 lines (37 loc) · 1.05 KB
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
39
40
<!doctype HTML>
<html>
<head>
<script>
// Method 1: Traditional postMessage (works when COOP allows window.opener)
if (window.opener) {
try {
window.opener.postMessage("done", document.location.origin);
} catch (e) {
console.warn("postMessage to opener failed:", e);
}
}
else {
console.warn("No window.opener", window.opener);
}
// Method 2: BroadcastChannel (works even when COOP severs window.opener)
// This is the fallback for environments like GoGuardian that inject COOP headers
if (typeof BroadcastChannel !== 'undefined') {
try {
let channel = new BroadcastChannel('pyret_auth');
channel.postMessage({ type: 'auth_complete' });
channel.close();
} catch (e) {
console.warn("BroadcastChannel failed:", e);
}
}
// Method 3: localStorage fallback for very old browsers without BroadcastChannel
// The opener can detect this via the 'storage' event
try {
localStorage.setItem('pyret_auth_complete', Date.now().toString());
} catch (e) {
console.warn("localStorage fallback failed:", e);
}
window.close();
</script>
</head>
</html>