-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: resolve adblock detection alert
- Loading branch information
1 parent
1e5cc15
commit 1bf07fb
Showing
3 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
type unsafeWindowType = typeof window & typeof globalThis; | ||
declare const unsafeWindow: unsafeWindowType; | ||
// eslint-disable-next-line no-negated-condition | ||
const win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window; | ||
/* eslint-disable no-eval */ | ||
import {useDebug, useBannedKeywords} from '../utils'; | ||
|
||
const debug = useDebug('[microShield:evalInterceptors]'); | ||
|
||
export const useEvalInterceptor = () => { | ||
const evalProxy = new Proxy(eval, { | ||
apply(target: typeof eval, thisArg: undefined | string, argLists: string[] | [string]) { | ||
if ((!argLists.length && typeof thisArg === 'undefined') || (!useBannedKeywords(argLists[0] ?? thisArg))) { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
return Reflect.apply(target, thisArg, argLists); | ||
} | ||
|
||
debug('eval:ban', argLists); | ||
}, | ||
}); | ||
Object.defineProperty(win, 'eval', { | ||
value: evalProxy, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters