Skip to content

Commit

Permalink
fix: deduplicate wxt:content-script-started
Browse files Browse the repository at this point in the history
> This fix prevents premature context invalidation
> fixes #1359
  • Loading branch information
DenizUgur committed Jan 22, 2025
1 parent a593cfb commit 98067bc
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class ContentScriptContext implements AbortController {
private isTopFrame = window.self === window.top;
private abortController: AbortController;
private locationWatcher = createLocationWatcher(this);
private receivedTimestamps = new Set<number>();

constructor(
private readonly contentScriptName: string,
Expand Down Expand Up @@ -246,6 +247,10 @@ export class ContentScriptContext implements AbortController {
event.data?.type === ContentScriptContext.SCRIPT_STARTED_MESSAGE_TYPE &&
event.data?.contentScriptName === this.contentScriptName
) {
// Deduplicate messages
if (this.receivedTimestamps.has(event.timeStamp)) return;
this.receivedTimestamps.add(event.timeStamp);

const wasFirst = isFirst;
isFirst = false;
if (wasFirst && options?.ignoreFirstEvent) return;
Expand Down

0 comments on commit 98067bc

Please sign in to comment.