|
@@ -91,19 +91,18 @@ export function openInNewTab(href: string) {
|
|
|
* Intercepts the specified event on the passed object and prevents it from being called if the called {@linkcode predicate} function returns a truthy value.
|
|
|
* If no predicate is specified, all events will be discarded.
|
|
|
* 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.
|
|
|
+ * Calling this function will set `Error.stackTraceLimit = 100` (if not already higher) to ensure the stack trace is preserved.
|
|
|
*/
|
|
|
export function interceptEvent<TEvtObj extends EventTarget, TPredicateEvt extends Event>(
|
|
|
eventObject: TEvtObj,
|
|
|
eventName: Parameters<TEvtObj["addEventListener"]>[0],
|
|
|
predicate: (event: TPredicateEvt) => boolean = () => true,
|
|
|
) {
|
|
|
- // default is between 10 and 100 on conventional browsers so this should hopefully be more than enough
|
|
|
+ // default is 25 on FF so this should hopefully be more than enough
|
|
|
// @ts-ignore
|
|
|
- if(typeof Error.stackTraceLimit === "number" && Error.stackTraceLimit < 1000) {
|
|
|
- // @ts-ignore
|
|
|
- Error.stackTraceLimit = 1000;
|
|
|
- }
|
|
|
+ Error.stackTraceLimit = Math.max(Error.stackTraceLimit, 100);
|
|
|
+ if(isNaN(Error.stackTraceLimit))
|
|
|
+ Error.stackTraceLimit = 100;
|
|
|
|
|
|
(function(original: typeof eventObject.addEventListener) {
|
|
|
// @ts-ignore
|
|
@@ -125,7 +124,7 @@ export function interceptEvent<TEvtObj extends EventTarget, TPredicateEvt extend
|
|
|
* Intercepts the specified event on the window object and prevents it from being called if the called {@linkcode predicate} function returns a truthy value.
|
|
|
* If no predicate is specified, all events will be discarded.
|
|
|
* 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.
|
|
|
+ * Calling this function will set `Error.stackTraceLimit = 100` (if not already higher) to ensure the stack trace is preserved.
|
|
|
*/
|
|
|
export function interceptWindowEvent<TEvtKey extends keyof WindowEventMap>(
|
|
|
eventName: TEvtKey,
|