Skip to content
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
10 changes: 6 additions & 4 deletions skills/browsing/chrome-ws
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ if (command === '--version' || command === '-v') {

const hostOverride = require('./host-override').createOverride();
const { createSession } = require('./chrome-ws-lib');
const { buildChromeArgs } = require('./lib/chrome-launcher-helpers');
const CHROME_DEBUG_HOST = hostOverride.getHost();
const CHROME_DEBUG_PORT = hostOverride.getPort();
const WS_OVERRIDE_ENABLED = hostOverride.isOverrideEnabled();
Expand Down Expand Up @@ -326,10 +327,11 @@ if (command === 'start') {
? 'C:\\temp\\chrome-debug'
: '/tmp/chrome-debug';

const chromeArgs = [
`--remote-debugging-port=${effectivePort}`,
`--user-data-dir=${userDataDir}`
];
const chromeArgs = buildChromeArgs({
chosenPort: effectivePort,
chromeUserDataDir: userDataDir,
chromeHeadless: false,
});

console.log(`Starting Chrome: ${chromePath}`);
const chrome = spawn(chromePath, chromeArgs, {
Expand Down
41 changes: 40 additions & 1 deletion test/cli-dispatch.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@
import { describe, it } from 'node:test';
import { strict as assert } from 'node:assert';
import { spawnSync } from 'node:child_process';
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import * as path from 'node:path';
import { fileURLToPath } from 'node:url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const CLI = path.join(__dirname, '..', 'skills', 'browsing', 'chrome-ws');

function runCLI(args, { timeoutMs = 5000 } = {}) {
function runCLI(args, { env = {}, timeoutMs = 5000 } = {}) {
return spawnSync('node', [CLI, ...args], {
encoding: 'utf8',
env: { ...process.env, ...env },
timeout: timeoutMs,
});
}
Expand Down Expand Up @@ -72,4 +75,40 @@ describe('chrome-ws CLI dispatch', () => {
'stop must not print the raw usage banner'
);
});

it('start uses the shared Chrome arg builder and honors CHROME_EXTRA_ARGS', () => {
const dir = path.join(tmpdir(), `chrome-ws-cli-args-${process.pid}-${Date.now()}`);
mkdirSync(dir, { recursive: true });
const fakeChrome = path.join(dir, 'fake-chrome');
const argsFile = path.join(dir, 'args.json');

writeFileSync(fakeChrome, `#!/usr/bin/env node
const fs = require('node:fs');
fs.writeFileSync(process.env.FAKE_CHROME_ARGS_FILE, JSON.stringify(process.argv.slice(2)));
`, { mode: 0o755 });

try {
const r = runCLI(['--port=49217', 'start'], {
env: {
CHROME_WS_BROWSER: fakeChrome,
CHROME_EXTRA_ARGS: '--headless=new --disable-gpu --flag-from-env',
FAKE_CHROME_ARGS_FILE: argsFile,
},
timeoutMs: 5000,
});

assert.equal(r.status, 1, 'fake Chrome never opens the debug port, so start should fail');
assert.ok(existsSync(argsFile), 'fake Chrome should have been spawned');

const args = JSON.parse(readFileSync(argsFile, 'utf8'));
assert.ok(args.includes('--remote-debugging-port=49217'));
assert.ok(args.some(a => a.startsWith('--user-data-dir=')));
assert.ok(args.includes('--no-first-run'), 'baseline shared-helper flag should be present');
assert.ok(args.includes('--headless=new'), 'CHROME_EXTRA_ARGS should be appended');
assert.ok(args.includes('--disable-gpu'), 'CHROME_EXTRA_ARGS should support multiple flags');
assert.ok(args.includes('--flag-from-env'), 'CHROME_EXTRA_ARGS should reach CLI start');
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
});