-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistentoevents.js
29 lines (26 loc) · 1.26 KB
/
listentoevents.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
(function () {
// Function to create a postMessage proxy for a given window
const createPostMessageProxy = (targetWindow, windowName = 'unknown') => {
const originalPostMessage = targetWindow.postMessage;
targetWindow.postMessage = function (message, targetOrigin, transfer) {
var isAngular1 = (message && message.source && message.source.startsWith('angular-devtools'));
var isAngular2 = message && (message.isIvy || message.isAngular);
var isTargetOrigin = targetOrigin === "*";
if (!isAngular1 && !isAngular2 && !isTargetOrigin) {
console.log(`[${windowName}] postMessage called with:`, { message, targetOrigin, transfer });
}
originalPostMessage.call(targetWindow, message, targetOrigin, transfer);
};
};
createPostMessageProxy(window, 'mainWindow');
// Apply proxy to iframes or other windows as needed
const iframes = document.querySelectorAll('iframe');
iframes.forEach((iframe, index) => {
try {
const iframeWindow = iframe.contentWindow;
createPostMessageProxy(iframeWindow, `iframe_${index}`);
} catch (e) {
console.warn('Cannot access iframe contentWindow:', e);
}
});
})();