diff --git a/src/adapter/adapter/addonManager.ts b/src/adapter/adapter/addonManager.ts index 064daec..f769e9b 100644 --- a/src/adapter/adapter/addonManager.ts +++ b/src/adapter/adapter/addonManager.ts @@ -23,6 +23,7 @@ export class AddonManager { private addonAttached = false; private addonActor: TabActorProxy | undefined = undefined; + private webExtensionActor: WebExtensionActorProxy | undefined = undefined; constructor( private readonly enableCRAWorkaround: boolean, @@ -53,11 +54,11 @@ export class AddonManager { } public async reloadAddon(): Promise { - if (!this.addonActor) { + if (!this.webExtensionActor) { throw 'Addon isn\'t attached'; } - await this.addonActor.reload(); + await this.webExtensionActor.reload(); } private async fetchAddonsAndAttach(rootActor: RootActorProxy, useConnect: boolean): Promise { @@ -73,14 +74,14 @@ export class AddonManager { (async () => { let consoleActor: ConsoleActorProxy; - let webExtensionActor = new WebExtensionActorProxy( + this.webExtensionActor = new WebExtensionActorProxy( addon, this.enableCRAWorkaround, this.debugSession.pathMapper, this.debugSession.firefoxDebugConnection); if (useConnect) { - [this.addonActor, consoleActor] = await webExtensionActor.connect(); + [this.addonActor, consoleActor] = await this.webExtensionActor.connect(); } else { - [this.addonActor, consoleActor] = await webExtensionActor.getTarget(); + [this.addonActor, consoleActor] = await this.webExtensionActor.getTarget(); } let threadAdapter = await this.debugSession.attachTabOrAddon( diff --git a/src/adapter/firefox/actorProxy/webExtension.ts b/src/adapter/firefox/actorProxy/webExtension.ts index aeb668c..af448e7 100644 --- a/src/adapter/firefox/actorProxy/webExtension.ts +++ b/src/adapter/firefox/actorProxy/webExtension.ts @@ -16,6 +16,7 @@ let log = Log.create('WebExtensionActorProxy'); export class WebExtensionActorProxy extends EventEmitter implements ActorProxy { private pendingConnectRequests = new PendingRequests<[TabActorProxy, ConsoleActorProxy]>(); + private pendingReloadRequests = new PendingRequests(); constructor( private readonly webExtensionInfo: FirefoxDebugProtocol.Addon, @@ -51,6 +52,16 @@ export class WebExtensionActorProxy extends EventEmitter implements ActorProxy { }) } + public reload(): Promise { + + log.debug(`Reloading ${this.name}`); + + return new Promise((resolve, reject) => { + this.pendingReloadRequests.enqueue({ resolve, reject }); + this.connection.sendRequest({ to: this.name, type: 'reload' }); + }); + } + public receiveResponse(response: FirefoxDebugProtocol.Response): void { if (response['form']) { @@ -74,7 +85,12 @@ export class WebExtensionActorProxy extends EventEmitter implements ActorProxy { this.connection.sendRequest({ to: this.name, type: 'connect' }); }, 100); } - + + } else if (Object.keys(response).length === 2) { + + log.debug('Received response to reload request'); + this.pendingReloadRequests.resolveOne(undefined); + } else { log.warn("Unknown message from WebExtensionActor: " + JSON.stringify(response));