-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathframed.js
41 lines (35 loc) · 857 Bytes
/
framed.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
38
39
40
41
let framed;
export async function isFramed() {
if (framed !== undefined) return framed;
if (window.D2L && window.D2L.IsNotAnIframedApp) {
framed = false;
return framed;
}
try {
if (window === window.parent) {
framed = false;
return framed;
}
} catch {
framed = false;
return framed;
}
framed = await Promise.race([
new Promise(resolve => {
const handleIsFramedResponse = evt => {
if (!evt || !evt.data || evt.data.isFramed === undefined) return;
window.removeEventListener('message', handleIsFramedResponse, false);
framed = evt.data.isFramed;
resolve(framed);
};
window.addEventListener('message', handleIsFramedResponse, false);
window.parent.postMessage('isFramedRequest', '*');
}),
new Promise(resolve => {
setTimeout(() => {
resolve(false);
}, 75);
})
]);
return framed;
}