Skip to content

fix: add missing timer clear methods to ContentScriptContext #1507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ContentScriptDefinition } from '../../types';
import { browser } from 'wxt/browser';
import { logger } from '../../sandbox/utils/logger';
import { ContentScriptDefinition } from '../../types';
import { WxtLocationChangeEvent, getUniqueEventName } from './custom-events';
import { createLocationWatcher } from './location-watcher';

Expand Down Expand Up @@ -163,6 +163,38 @@ export class ContentScriptContext implements AbortController {
return id;
}

/**
* Clears a timeout set by ctx.setTimeout.
*/
clearTimeout(id: number | null): void {
if (id !== null) {
clearTimeout(id);
}
}
Comment on lines +169 to +173
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be | undefined if we decide to keep them. And we don't need an if-statement either.

Suggested change
clearTimeout(id: number | null): void {
if (id !== null) {
clearTimeout(id);
}
}
clearTimeout(id: number | undefined): void {
clearTimeout(id);
}

Same applies to clearInterval.


/**
* Clears an interval set by ctx.setInterval.
*/
clearInterval(id: number | null): void {
if (id !== null) {
clearInterval(id);
}
}

/**
* Cancels an animation frame request set by ctx.requestAnimationFrame.
*/
cancelAnimationFrame(id: number): void {
cancelAnimationFrame(id);
}

/**
* Cancels an idle callback request set by ctx.requestIdleCallback.
*/
cancelIdleCallback(id: number): void {
cancelIdleCallback(id);
}

/**
* Call `target.addEventListener` and remove the event listener when the context is invalidated.
*
Expand Down