|
@@ -140,12 +140,13 @@ export function openInNewTab(href: string) {
|
|
|
|
|
|
/**
|
|
|
* Intercepts the specified event on the passed object and prevents it from being called if the called `predicate` function returns a truthy value.
|
|
|
- * Calling this function will set the `stackTraceLimit` to 1000 to ensure the stack trace is preserved.
|
|
|
+ * This function should be called as soon as possible (I recommend using `@run-at document-start`), as it will only intercept events that are added after this function is called.
|
|
|
+ * Calling this function will set the `Error.stackTraceLimit` to 1000 to ensure the stack trace is preserved.
|
|
|
*/
|
|
|
export function interceptEvent<TEvtObj extends EventTarget>(eventObject: TEvtObj, eventName: Parameters<TEvtObj["addEventListener"]>[0], predicate: () => boolean) {
|
|
|
// default is between 10 and 100 on conventional browsers so this should hopefully be more than enough
|
|
|
// @ts-ignore
|
|
|
- if(Error.stackTraceLimit < 1000) {
|
|
|
+ if(typeof Error.stackTraceLimit === "number" && Error.stackTraceLimit < 1000) {
|
|
|
// @ts-ignore
|
|
|
Error.stackTraceLimit = 1000;
|
|
|
}
|
|
@@ -164,7 +165,8 @@ export function interceptEvent<TEvtObj extends EventTarget>(eventObject: TEvtObj
|
|
|
|
|
|
/**
|
|
|
* Intercepts the specified event on the window object and prevents it from being called if the called `predicate` function returns a truthy value.
|
|
|
- * Calling this function will set the `stackTraceLimit` to 1000 to ensure the stack trace is preserved.
|
|
|
+ * This function should be called as soon as possible (I recommend using `@run-at document-start`), as it will only intercept events that are added after this function is called.
|
|
|
+ * Calling this function will set the `Error.stackTraceLimit` to 1000 to ensure the stack trace is preserved.
|
|
|
*/
|
|
|
export function interceptWindowEvent(eventName: keyof WindowEventMap, predicate: () => boolean) {
|
|
|
return interceptEvent(getUnsafeWindow(), eventName, predicate);
|