Skip to content
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

"Firefox: Reload add-on" doesn't reload web extension #303

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions src/adapter/adapter/addonManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -53,11 +54,11 @@ export class AddonManager {
}

public async reloadAddon(): Promise<void> {
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<void> {
Expand All @@ -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(
Expand Down
18 changes: 17 additions & 1 deletion src/adapter/firefox/actorProxy/webExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>();

constructor(
private readonly webExtensionInfo: FirefoxDebugProtocol.Addon,
Expand Down Expand Up @@ -51,6 +52,16 @@ export class WebExtensionActorProxy extends EventEmitter implements ActorProxy {
})
}

public reload(): Promise<void> {

log.debug(`Reloading ${this.name}`);

return new Promise<void>((resolve, reject) => {
this.pendingReloadRequests.enqueue({ resolve, reject });
this.connection.sendRequest({ to: this.name, type: 'reload' });
});
}

public receiveResponse(response: FirefoxDebugProtocol.Response): void {

if (response['form']) {
Expand All @@ -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));
Expand Down