From b6758ca9faf71b4cafe3657bf228be497389c2a4 Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 17 Oct 2023 15:33:55 -0500 Subject: [PATCH] fix(firefox): Stop extending `AbortController` to fix crash in content scripts (#176) --- src/client/utils/ContentScriptContext.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/client/utils/ContentScriptContext.ts b/src/client/utils/ContentScriptContext.ts index 88d18cbb..3f0d67a7 100644 --- a/src/client/utils/ContentScriptContext.ts +++ b/src/client/utils/ContentScriptContext.ts @@ -3,23 +3,23 @@ import { browser } from '../browser'; import { logger } from './logger'; /** - * Extends [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController). + * Implements [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController). * Used to detect and stop content script code when the script is invalidated. * * It also provides several utilities like `ctx.setTimeout` and `ctx.setInterval` that should be used in * content scripts instead of `window.setTimeout` or `window.setInterval`. */ -export class ContentScriptContext extends AbortController { +export class ContentScriptContext implements AbortController { private static SCRIPT_STARTED_MESSAGE_TYPE = 'wxt:content-script-started'; #isTopFrame = window.self === window.top; + #abortController: AbortController; constructor( private readonly contentScriptName: string, public readonly options?: Omit, ) { - super(); - + this.#abortController = new AbortController(); if (this.#isTopFrame) { this.#stopOldScripts(); } @@ -29,6 +29,14 @@ export class ContentScriptContext extends AbortController { }); } + get signal() { + return this.#abortController.signal; + } + + abort(reason?: any): void { + return this.#abortController.abort(reason); + } + get isInvalid(): boolean { if (browser.runtime.id == null) { this.notifyInvalidated(); // Sets `signal.aborted` to true