From 030f23d2e9044203ea824e70995535bb60d64978 Mon Sep 17 00:00:00 2001 From: Aaron Date: Thu, 5 Jun 2025 00:38:51 -0500 Subject: [PATCH] docs: Update JSDoc with ways to cancel timeouts and intervals set by content script context --- packages/wxt/src/utils/content-script-context.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/wxt/src/utils/content-script-context.ts b/packages/wxt/src/utils/content-script-context.ts index 5a488019..22d68d59 100644 --- a/packages/wxt/src/utils/content-script-context.ts +++ b/packages/wxt/src/utils/content-script-context.ts @@ -118,6 +118,8 @@ export class ContentScriptContext implements AbortController { /** * Wrapper around `window.setInterval` that automatically clears the interval when invalidated. + * + * Intervals can be cleared by calling the normal `clearInterval` function. */ setInterval(handler: () => void, timeout?: number): number { const id = setInterval(() => { @@ -129,6 +131,8 @@ export class ContentScriptContext implements AbortController { /** * Wrapper around `window.setTimeout` that automatically clears the interval when invalidated. + * + * Timeouts can be cleared by calling the normal `setTimeout` function. */ setTimeout(handler: () => void, timeout?: number): number { const id = setTimeout(() => { @@ -141,6 +145,8 @@ export class ContentScriptContext implements AbortController { /** * Wrapper around `window.requestAnimationFrame` that automatically cancels the request when * invalidated. + * + * Callbacks can be canceled by calling the normal `cancelAnimationFrame` function. */ requestAnimationFrame(callback: FrameRequestCallback): number { const id = requestAnimationFrame((...args) => { @@ -154,6 +160,8 @@ export class ContentScriptContext implements AbortController { /** * Wrapper around `window.requestIdleCallback` that automatically cancels the request when * invalidated. + * + * Callbacks can be canceled by calling the normal `cancelIdleCallback` function. */ requestIdleCallback( callback: IdleRequestCallback, @@ -170,6 +178,8 @@ export class ContentScriptContext implements AbortController { /** * Call `target.addEventListener` and remove the event listener when the context is invalidated. * + * Listeners can be canceled by calling the normal `removeEventListener` function. + * * Includes additional events useful for content scripts: * * - `"wxt:locationchange"` - Triggered when HTML5 history mode is used to change URL. Content