Skip to content

Commit

Permalink
launch Microsoft Edge with specified args (#623)
Browse files Browse the repository at this point in the history
* add option to enable cors

* correct comment

* changing to browserArgs

* fix type

Co-authored-by: paul <guipeng@daojia-inc.com>
  • Loading branch information
gp5251 and paul authored Nov 23, 2021
1 parent 08cef84 commit 335d193
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@
"description": "Launch Microsoft Edge in headless mode. (requires relaunching Visual Studio Code)",
"default": false
},
"vscode-edge-devtools.browserArgs": {
"type": "array",
"description": "Launch Microsoft Edge with specified args. (requires relaunching Visual Studio Code)",
"items": {
"type": "string"
},
"default": []
},
"vscode-edge-devtools.timeout": {
"type": "number",
"description": "The number of milliseconds that the Microsoft Edge Tools will keep trying to attach the browser before timing out",
Expand Down
17 changes: 17 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,16 @@ export async function launchBrowser(browserPath: string, port: number, targetUrl

const headless: boolean = isHeadlessEnabled();

let browserArgs: string[] = getBrowserArgs();
browserArgs = browserArgs.filter(arg => !arg.startsWith('--remote-debugging-port') && arg !== targetUrl);

if (userDataDir) {
args.unshift(`--user-data-dir=${userDataDir}`);
browserArgs = browserArgs.filter(arg => !arg.startsWith('--user-data-dir'));
}

if (browserArgs.length) {
args.unshift(...browserArgs);
}

const browserInstance = await puppeteer.launch({executablePath: browserPath, args, headless});
Expand Down Expand Up @@ -611,6 +619,15 @@ export function isHeadlessEnabled(): boolean {
return headless;
}

/**
* get the command line args which are passed to the browser.
*/
export function getBrowserArgs(): string[] {
const settings = vscode.workspace.getConfiguration(SETTINGS_STORE_NAME);
const browserArgs: string[] = settings.get('browserArgs') || [];
return browserArgs.map(arg => arg.trim());
}

/**
* Replaces the workspaceFolder placeholder in a specified path, returns the
* given path with file disk path.
Expand Down

0 comments on commit 335d193

Please sign in to comment.