Skip to content

Commit 030f23d

Browse files
committed
docs: Update JSDoc with ways to cancel timeouts and intervals set by content script context
1 parent 6be9a4e commit 030f23d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

packages/wxt/src/utils/content-script-context.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ export class ContentScriptContext implements AbortController {
118118

119119
/**
120120
* Wrapper around `window.setInterval` that automatically clears the interval when invalidated.
121+
*
122+
* Intervals can be cleared by calling the normal `clearInterval` function.
121123
*/
122124
setInterval(handler: () => void, timeout?: number): number {
123125
const id = setInterval(() => {
@@ -129,6 +131,8 @@ export class ContentScriptContext implements AbortController {
129131

130132
/**
131133
* Wrapper around `window.setTimeout` that automatically clears the interval when invalidated.
134+
*
135+
* Timeouts can be cleared by calling the normal `setTimeout` function.
132136
*/
133137
setTimeout(handler: () => void, timeout?: number): number {
134138
const id = setTimeout(() => {
@@ -141,6 +145,8 @@ export class ContentScriptContext implements AbortController {
141145
/**
142146
* Wrapper around `window.requestAnimationFrame` that automatically cancels the request when
143147
* invalidated.
148+
*
149+
* Callbacks can be canceled by calling the normal `cancelAnimationFrame` function.
144150
*/
145151
requestAnimationFrame(callback: FrameRequestCallback): number {
146152
const id = requestAnimationFrame((...args) => {
@@ -154,6 +160,8 @@ export class ContentScriptContext implements AbortController {
154160
/**
155161
* Wrapper around `window.requestIdleCallback` that automatically cancels the request when
156162
* invalidated.
163+
*
164+
* Callbacks can be canceled by calling the normal `cancelIdleCallback` function.
157165
*/
158166
requestIdleCallback(
159167
callback: IdleRequestCallback,
@@ -170,6 +178,8 @@ export class ContentScriptContext implements AbortController {
170178
/**
171179
* Call `target.addEventListener` and remove the event listener when the context is invalidated.
172180
*
181+
* Listeners can be canceled by calling the normal `removeEventListener` function.
182+
*
173183
* Includes additional events useful for content scripts:
174184
*
175185
* - `"wxt:locationchange"` - Triggered when HTML5 history mode is used to change URL. Content

0 commit comments

Comments
 (0)