Skip to content

Commit 7d46d15

Browse files
saintsebastiankumar303
authored andcommitted
feat: Added web-ext run --start-url to start Firefox on a specific page (#709)
1 parent 3a31bcc commit 7d46d15

4 files changed

Lines changed: 66 additions & 8 deletions

File tree

src/cmd/run.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ export type CmdRunParams = {
153153
noReload: boolean,
154154
browserConsole: boolean,
155155
customPrefs?: FirefoxPreferences,
156+
startUrl?: string | Array<string>,
156157
};
157158

158159
export type CmdRunOptions = {
@@ -165,7 +166,7 @@ export default async function run(
165166
{
166167
sourceDir, artifactsDir, firefox, firefoxProfile,
167168
preInstall = false, noReload = false,
168-
browserConsole = false, customPrefs,
169+
browserConsole = false, customPrefs, startUrl,
169170
}: CmdRunParams,
170171
{
171172
firefoxApp = defaultFirefoxApp,
@@ -197,6 +198,7 @@ export default async function run(
197198
manifestData,
198199
profilePath: firefoxProfile,
199200
customPrefs,
201+
startUrl,
200202
});
201203

202204
const profile = await runner.getProfile();
@@ -269,6 +271,7 @@ export type ExtensionRunnerParams = {
269271
firefox: string,
270272
browserConsole: boolean,
271273
customPrefs?: FirefoxPreferences,
274+
startUrl?: string | Array<string>,
272275
};
273276

274277
export class ExtensionRunner {
@@ -279,11 +282,12 @@ export class ExtensionRunner {
279282
firefox: string;
280283
browserConsole: boolean;
281284
customPrefs: FirefoxPreferences;
285+
startUrl: ?string | ?Array<string>;
282286

283287
constructor(
284288
{
285289
firefoxApp, sourceDir, manifestData,
286-
profilePath, firefox, browserConsole,
290+
profilePath, firefox, browserConsole, startUrl,
287291
customPrefs = {},
288292
}: ExtensionRunnerParams
289293
) {
@@ -294,6 +298,7 @@ export class ExtensionRunner {
294298
this.firefox = firefox;
295299
this.browserConsole = browserConsole;
296300
this.customPrefs = customPrefs;
301+
this.startUrl = startUrl;
297302
}
298303

299304
getProfile(): Promise<FirefoxProfile> {
@@ -329,12 +334,18 @@ export class ExtensionRunner {
329334

330335
run(profile: FirefoxProfile): Promise<FirefoxProcess> {
331336
const binaryArgs = [];
332-
const {firefoxApp, firefox} = this;
337+
const {firefoxApp, firefox, startUrl} = this;
333338
if (this.browserConsole) {
334339
binaryArgs.push('-jsconsole');
335340
}
336-
return firefoxApp.run(
337-
profile, {firefoxBinary: firefox, binaryArgs}
338-
);
341+
if (startUrl) {
342+
const urls = Array.isArray(startUrl) ? startUrl : [startUrl];
343+
for (const url of urls) {
344+
binaryArgs.push('--url', url);
345+
}
346+
}
347+
return firefoxApp.run(profile, {
348+
firefoxBinary: firefox, binaryArgs,
349+
});
339350
}
340351
}

src/program.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,13 @@ Example: $0 --help run.
316316
type: 'string',
317317
coerce: coerceCLICustomPreference,
318318
},
319+
'start-url': {
320+
alias: ['u', 'url'],
321+
describe: 'Launch firefox at specified page',
322+
demand: false,
323+
requiresArg: true,
324+
type: 'string',
325+
},
319326
'browser-console': {
320327
alias: ['bc'],
321328
describe: 'Open the DevTools Browser Console.',

tests/unit/test-cmd/test.run.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,34 @@ describe('run', () => {
127127
});
128128
});
129129

130+
it('passes single url parameter to Firefox when specified', () => {
131+
const cmd = prepareRun();
132+
const {firefoxApp} = cmd.options;
133+
const expectedBinaryArgs = ['--url', 'www.example.com'];
134+
135+
return cmd.run({startUrl: 'www.example.com'}).then(() => {
136+
assert.ok(firefoxApp.run.called);
137+
assert.deepEqual(firefoxApp.run.firstCall.args[1].binaryArgs,
138+
expectedBinaryArgs);
139+
});
140+
});
141+
142+
it('passes multiple url parameters to Firefox when specified', () => {
143+
const cmd = prepareRun();
144+
const {firefoxApp} = cmd.options;
145+
const expectedBinaryArgs = [
146+
'--url', 'www.one.com', '--url', 'www.two.com', '--url', 'www.three.com',
147+
];
148+
149+
return cmd.run({startUrl: [
150+
'www.one.com', 'www.two.com', 'www.three.com',
151+
]}).then(() => {
152+
assert.ok(firefoxApp.run.called);
153+
assert.deepEqual(firefoxApp.run.firstCall.args[1].binaryArgs,
154+
expectedBinaryArgs);
155+
});
156+
});
157+
130158
it('passes -jsconsole when --browser-console is specified', () => {
131159
const cmd = prepareRun();
132160
const {firefoxApp} = cmd.options;

tests/unit/test.program.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,20 @@ describe('program.main', () => {
368368
});
369369
});
370370

371+
it('passes the url of a firefox binary when specified', () => {
372+
const fakeCommands = fake(commands, {
373+
run: () => Promise.resolve(),
374+
});
375+
return execProgram(
376+
['run', '--start-url', 'www.example.com'],
377+
{commands: fakeCommands})
378+
.then(() => {
379+
assert.equal(fakeCommands.run.called, true);
380+
assert.equal(fakeCommands.run.firstCall.args[0].startUrl,
381+
'www.example.com');
382+
});
383+
});
384+
371385
it('opens browser console when --browser-console is specified', () => {
372386
const fakeCommands = fake(commands, {
373387
run: () => Promise.resolve(),
@@ -396,10 +410,8 @@ describe('program.main', () => {
396410
assert.equal(customPrefs.prop2, 'value2');
397411
});
398412
});
399-
400413
});
401414

402-
403415
describe('program.defaultVersionGetter', () => {
404416
const root = path.join(__dirname, '..', '..');
405417

0 commit comments

Comments
 (0)