You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+13-7Lines changed: 13 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -529,11 +529,12 @@ Usage:
529
529
interceptEvent(
530
530
eventObject: EventTarget,
531
531
eventName: string,
532
-
predicate: (event:Event) =>boolean
532
+
predicate?: (event:Event) =>boolean
533
533
): void
534
534
```
535
535
536
536
Intercepts all events dispatched on the `eventObject` and prevents the listeners from being called as long as the predicate function returns a truthy value.
537
+
If no predicate is specified, all events will be discarded.
537
538
Calling this function will set the `Error.stackTraceLimit` to 1000 (if it's not already higher) to ensure the stack trace is preserved.
538
539
539
540
⚠️ This function should be called as soon as possible (I recommend using `@run-atdocument-start`), as it will only intercept events that are *attached* after this function is called.
@@ -544,8 +545,12 @@ Calling this function will set the `Error.stackTraceLimit` to 1000 (if it's not
returntrue; // prevent all click events on the body element
548
+
// prevent all click events on <a> elements within the entire <body>
549
+
if(event.targetinstanceofHTMLAnchorElement) {
550
+
console.log("Intercepting click event:", event);
551
+
returntrue;
552
+
}
553
+
returnfalse; // allow all other click events through
549
554
});
550
555
```
551
556
@@ -558,11 +563,12 @@ Usage:
558
563
```ts
559
564
interceptWindowEvent(
560
565
eventName: string,
561
-
predicate: (event:Event) =>boolean
566
+
predicate?: (event:Event) =>boolean
562
567
): void
563
568
```
564
569
565
570
Intercepts all events dispatched on the `window` object and prevents the listeners from being called as long as the predicate function returns a truthy value.
571
+
If no predicate is specified, all events will be discarded.
566
572
This is essentially the same as [`interceptEvent()`](#interceptevent), but automatically uses the `unsafeWindow` (or falls back to regular `window`).
567
573
568
574
⚠️ This function should be called as soon as possible (I recommend using `@run-atdocument-start`), as it will only intercept events that are *attached* after this function is called.
@@ -573,9 +579,9 @@ This is essentially the same as [`interceptEvent()`](#interceptevent), but autom
Copy file name to clipboardExpand all lines: lib/dom.ts
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -87,6 +87,7 @@ export function openInNewTab(href: string) {
87
87
88
88
/**
89
89
* Intercepts the specified event on the passed object and prevents it from being called if the called {@linkcode predicate} function returns a truthy value.
90
+
* If no predicate is specified, all events will be discarded.
90
91
* 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.
91
92
* Calling this function will set the `Error.stackTraceLimit` to 1000 to ensure the stack trace is preserved.
* Intercepts the specified event on the window object and prevents it from being called if the called {@linkcode predicate} function returns a truthy value.
124
+
* If no predicate is specified, all events will be discarded.
123
125
* 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.
124
126
* Calling this function will set the `Error.stackTraceLimit` to 1000 to ensure the stack trace is preserved.
0 commit comments