From 028ea3833955e50160cdb7b04ea5eeecf8643a2a Mon Sep 17 00:00:00 2001 From: Esteban Pasquier <34367991+XoddX@users.noreply.github.com> Date: Tue, 5 Apr 2022 11:15:26 +0200 Subject: [PATCH] Add ability to open multiple urls at once --- .gitignore | 1 + README.md | 2 +- src/chrome-launcher.ts | 7 ++++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index f06235c46..fa4987385 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules dist +.idea \ No newline at end of file diff --git a/README.md b/README.md index 9dffd4873..22c05924f 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ npm install chrome-launcher // (optional) Starting URL to open the browser with // Default: `about:blank` - startingUrl: string; + startingUrl: string | Array; // (optional) Logging level // Default: 'silent' diff --git a/src/chrome-launcher.ts b/src/chrome-launcher.ts index 6d65e3d9f..b2bdad6ef 100644 --- a/src/chrome-launcher.ts +++ b/src/chrome-launcher.ts @@ -29,7 +29,7 @@ const instances = new Set(); type JSONLike =|{[property: string]: JSONLike}|readonly JSONLike[]|string|number|boolean|null; export interface Options { - startingUrl?: string; + startingUrl?: string|Array; chromeFlags?: Array; prefs?: Record; port?: number; @@ -111,7 +111,7 @@ async function killAll(): Promise> { class Launcher { private tmpDirandPidFileReady = false; private pidFile: string; - private startingUrl: string; + private startingUrl: string|Array; private outFile?: number; private errFile?: number; private chromePath?: string; @@ -139,6 +139,7 @@ class Launcher { // choose the first one (default) this.startingUrl = defaults(this.opts.startingUrl, 'about:blank'); + this.startingUrl = typeof this.startingUrl === 'string' ? [this.startingUrl] : this.startingUrl; this.chromeFlags = defaults(this.opts.chromeFlags, []); this.prefs = defaults(this.opts.prefs, {}); this.requestedPort = defaults(this.opts.port, 0); @@ -176,7 +177,7 @@ class Launcher { } flags.push(...this.chromeFlags); - flags.push(this.startingUrl); + flags.push(...this.startingUrl); return flags; }