issue with eventlistener fixed

This commit is contained in:
nick-delirium 2024-10-14 09:52:02 +02:00
parent 6b84ba2500
commit 4ea1321d17
No known key found for this signature in database
GPG key ID: 93ABD695DF5FDBA0
6 changed files with 24 additions and 4 deletions

Binary file not shown.

View file

@ -0,0 +1 @@
nodeLinker: node-modules

Binary file not shown.

View file

@ -32,9 +32,10 @@
"@jest/globals": "^29.3.1",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "0.4.4",
"@typescript-eslint/eslint-plugin": "^5.30.0",
"@typescript-eslint/parser": "^5.30.0",
"eslint": "^7.8.0",
"eslint": "^8.57.1",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.1",
"jest": "^29.3.1",
@ -43,7 +44,6 @@
"prettier": "^3.0.3",
"replace-in-files": "^2.0.3",
"rollup": "^4.1.4",
"rollup-plugin-terser": "^7.0.2",
"semver": "^6.3.0",
"ts-jest": "^29.0.3",
"typescript": "^4.9.4"
@ -65,5 +65,6 @@
"*.{json,md,html,js,jsx,ts,tsx}": [
"prettier --write"
]
}
},
"packageManager": "yarn@4.5.0"
}

View file

@ -1,6 +1,6 @@
import resolve from '@rollup/plugin-node-resolve'
import { babel } from '@rollup/plugin-babel'
import { terser } from 'rollup-plugin-terser'
import terser from '@rollup/plugin-terser';
export default {
input: 'build/webworker/index.js',

View file

@ -95,6 +95,17 @@ export function canAccessIframe(iframe: HTMLIFrameElement) {
}
}
export function canAccessTarget(target: any) {
try {
if (target.contentWindow) {
// If this property is inaccessible, it will throw due to cross-origin restrictions
return Boolean(target.contentWindow.location)
}
} catch (e) {
return false
}
}
function dec2hex(dec: number) {
return dec.toString(16).padStart(2, '0')
}
@ -148,6 +159,10 @@ export function createEventListener(
capture?: boolean,
angularMode?: boolean,
) {
// we need to check if target is crossorigin frame or no and if we can access it
if (target instanceof HTMLIFrameElement && !canAccessIframe(target)) {
return
}
let safeAddEventListener: 'addEventListener'
if (angularMode) {
safeAddEventListener = ngSafeBrowserMethod('addEventListener') as 'addEventListener'
@ -174,6 +189,9 @@ export function deleteEventListener(
capture?: boolean,
angularMode?: boolean,
) {
if (target instanceof HTMLIFrameElement && !canAccessIframe(target)) {
return
}
let safeRemoveEventListener: 'removeEventListener'
if (angularMode) {
safeRemoveEventListener = ngSafeBrowserMethod('removeEventListener') as 'removeEventListener'