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

feat: Introduce webext run --devtools to open DevTools for the installed add-on right away. #2488

Merged
merged 2 commits into from
Sep 12, 2022
Merged
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
3 changes: 3 additions & 0 deletions src/cmd/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const log = createLogger(import.meta.url);
export type CmdRunParams = {|
artifactsDir: string,
browserConsole: boolean,
devtools: boolean,
pref?: FirefoxPreferences,
firefox: string,
firefoxProfile?: string,
Expand Down Expand Up @@ -75,6 +76,7 @@ export default async function run(
{
artifactsDir,
browserConsole = false,
devtools = false,
pref,
firefox,
firefoxProfile,
Expand Down Expand Up @@ -174,6 +176,7 @@ export default async function run(
profilePath: firefoxProfile,
customPrefs,
browserConsole,
devtools,
preInstall,

// Firefox runner injected dependencies.
Expand Down
5 changes: 4 additions & 1 deletion src/extension-runners/firefox-desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type {FirefoxInfo} from '../firefox/index'; // eslint-disable-line import
type FirefoxDesktopSpecificRunnerParams = {|
customPrefs?: FirefoxPreferences,
browserConsole: boolean,
devtools: boolean,
firefoxBinary: string,
preInstall: boolean,

Expand Down Expand Up @@ -212,6 +213,7 @@ export class FirefoxDesktopExtensionRunner {
async startFirefoxInstance() {
const {
browserConsole,
devtools,
extensions,
firefoxBinary,
preInstall,
Expand Down Expand Up @@ -241,6 +243,7 @@ export class FirefoxDesktopExtensionRunner {
firefoxBinary,
binaryArgs,
extensions,
devtools,
});

this.runningInfo.firefox.on('close', () => {
Expand All @@ -262,7 +265,7 @@ export class FirefoxDesktopExtensionRunner {
for (const extension of extensions) {
try {
const addonId = await (
remoteFirefox.installTemporaryAddon(extension.sourceDir)
remoteFirefox.installTemporaryAddon(extension.sourceDir, devtools)
.then((installResult: FirefoxRDPResponseAddon) => {
return installResult.addon.id;
})
Expand Down
12 changes: 9 additions & 3 deletions src/firefox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export type FirefoxRunOptions = {
binaryArgs?: Array<string>,
args?: Array<any>,
extensions: Array<Extension>,
devtools: boolean,
};

/*
Expand All @@ -103,6 +104,7 @@ export async function run(
firefoxBinary,
binaryArgs,
extensions,
devtools,
}: FirefoxRunOptions = {}
): Promise<FirefoxInfo> {

Expand Down Expand Up @@ -164,9 +166,13 @@ export async function run(
throw error;
});

log.info(
'Use --verbose or open Tools > Web Developer > Browser Console ' +
'to see logging');
if (!devtools) {
log.info('Use --verbose or --devtools to see logging');
}
if (devtools) {
log.info('More info about WebExtensions debugging:');
log.info('https://extensionworkshop.com/documentation/develop/debugging/');
}

firefox.stderr.on('data', (data) => {
log.debug(`Firefox stderr: ${data.toString().trim()}`);
Expand Down
4 changes: 3 additions & 1 deletion src/firefox/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ export class RemoteFirefox {
}

async installTemporaryAddon(
addonPath: string
addonPath: string,
openDevTools?: boolean
): Promise<FirefoxRDPResponseAddon> {
const addonsActor = await this.getAddonsActor();

Expand All @@ -140,6 +141,7 @@ export class RemoteFirefox {
to: addonsActor,
type: 'installTemporaryAddon',
addonPath,
openDevTools,
});
log.debug(`installTemporaryAddon: ${JSON.stringify(response)}`);
log.info(`Installed ${addonPath} as a temporary add-on`);
Expand Down
6 changes: 6 additions & 0 deletions src/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,12 @@ Example: $0 --help run.
demandOption: false,
type: 'array',
},
'devtools': {
describe: 'Open the DevTools for the installed add-on ' +
'(Firefox 106 and later)',
demandOption: false,
type: 'boolean',
},
'browser-console': {
alias: ['bc'],
describe: 'Open the DevTools Browser Console.',
Expand Down
1 change: 1 addition & 0 deletions tests/functional/fake-firefox-binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const REQUEST_INSTALL_ADDON = {
to: 'fakeAddonsActor',
type: 'installTemporaryAddon',
addonPath: process.env.addonPath,
openDevTools: false, // Introduced in Firefox 106 (Bug 1787409 / Bug 1789245)
};
const REPLY_INSTALL_ADDON = {
from: 'fakeAddonsActor',
Expand Down
39 changes: 38 additions & 1 deletion tests/unit/test-firefox/test.firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import {fs} from 'mz';
import * as firefox from '../../../src/firefox/index.js';
import {onlyInstancesOf, UsageError, WebExtError} from '../../../src/errors.js';
import {withTempDir} from '../../../src/util/temp-dir.js';
import {
consoleStream, // instance is imported to inspect logged messages
} from '../../../src/util/logger.js';
import {
basicManifest,
fixturePath,
Expand Down Expand Up @@ -240,6 +243,41 @@ describe('firefox', () => {
});
});

it('logs link to debugging docs', async () => {
const runner = createFakeFxRunner();
consoleStream.flushCapturedLogs();
consoleStream.startCapturing();

const expectedMessage = 'More info about WebExtensions debugging:';
const expectedURLToDocs =
'https://extensionworkshop.com/documentation/develop/debugging/';
await runFirefox({fxRunner: runner, devtools: false});
assert.notOk(consoleStream.capturedMessages.find(
(msg) => msg.includes(expectedMessage)
));
assert.notOk(consoleStream.capturedMessages.find(
(msg) => msg.includes(expectedURLToDocs)
));

consoleStream.flushCapturedLogs();

await runFirefox({fxRunner: runner, devtools: true});
const foundMessage = consoleStream.capturedMessages.find(
(msg) => msg.includes(expectedMessage)
);
const foundDocURL = consoleStream.capturedMessages.find(
(msg) => msg.includes(expectedURLToDocs)
);

// Expect the logs to be found.
assert.ok(foundMessage);
assert.ok(foundDocURL);

// Expected to be emitted as info level logs.
assert.ok(foundMessage?.includes('[info]'));
assert.ok(foundDocURL?.includes('[info]'));
});

});

describe('copyProfile', () => {
Expand Down Expand Up @@ -1003,7 +1041,6 @@ describe('firefox', () => {
sinon.assert.calledOnce(fakeAsyncFsStat);
}
));

});

});
4 changes: 2 additions & 2 deletions tests/unit/test-firefox/test.remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,11 @@ describe('firefox.remote', () => {
const addonsActor = 'addons1.actor.conn';
const addonPath = '/path/to/addon';

client.request.withArgs({
client.request.withArgs(sinon.match({
type: 'installTemporaryAddon',
to: addonsActor,
addonPath,
}).resolves({
})).resolves({
addon: {id: 'abc123@temporary-addon'},
});

Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test.program.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,21 @@ describe('program.main', () => {
});
});

it('opens devtools when --devtools is specified', () => {
const fakeCommands = fake(commands, {
run: () => Promise.resolve(),
});
return execProgram(
['run', '--devtools'],
{commands: fakeCommands})
.then(() => {
sinon.assert.calledWithMatch(
fakeCommands.run,
{devtools: true}
);
});
});

async function testWatchFileOption(watchFile) {
const fakeCommands = fake(commands, {
run: () => Promise.resolve(),
Expand Down