Files
pbakaus_impeccable/tests/detect-url-launch.test.mjs
T
Vinaywho 33d7684c06 fix(detect): use system Chrome on Windows to stop GPU crash-loop window (#372)
On Windows, `impeccable detect <url>` flashed a persistent black window during
scans. The scan uses puppeteer's bundled Chrome, which runs from an untrusted
user-cache path; Windows blocks its GPU process, so it crash-loops and flashes a
compositor surface on every retry. It is not a real application window (not in
Alt+Tab, not clickable, invisible to window enumeration) and not malware.

Prefer the system-installed Chrome via channel:'chrome' on Windows, which runs
from a trusted location with a healthy GPU: no crash loop, no window. Fall back
to the bundled browser when Chrome is not installed. Scoped to Windows only, so
mac and linux keep the pinned bundled build for consistent measurement. Both
render on hardware GPU, so contrast measurement is unaffected.

Also routes both launch sites through one helper and fixes a pre-existing bug
where detectUrl hardcoded headless:true instead of honoring options.headless.

Tests: new tests/detect-url-launch.test.mjs covers the launch choice per
platform (Windows prefers channel:'chrome' and falls back to bundled;
non-Windows never attempts it), wired into the detector suite. Verified on
Windows 11 / Chrome 150: zero GPU crashes, window gone, findings unchanged.

This change was prepared with AI assistance.
2026-07-22 20:29:18 +05:30

82 lines
2.7 KiB
JavaScript

import { describe, test, expect, afterEach } from 'bun:test';
import { launchBrowser } from '../cli/engine/engines/browser/detect-url.mjs';
// launchBrowser prefers the system-installed Chrome on Windows to dodge the
// bundled-Chrome GPU crash-loop (issue #372), and keeps the pinned bundled
// build everywhere else. The function takes the puppeteer module as a
// parameter, so a fake lets us assert the launch strategy without a real
// browser or a real OS.
const realPlatform = Object.getOwnPropertyDescriptor(process, 'platform');
function setPlatform(value) {
Object.defineProperty(process, 'platform', { value, configurable: true });
}
afterEach(() => {
Object.defineProperty(process, 'platform', realPlatform);
});
function makePuppeteer({ failChannel = false } = {}) {
const calls = [];
const fakeBrowser = { __fake: true };
return {
calls,
fakeBrowser,
mod: {
default: {
async launch(opts) {
calls.push(opts);
if (failChannel && opts.channel === 'chrome') {
throw new Error('Could not find Chrome (channel: chrome)');
}
return fakeBrowser;
},
},
},
};
}
describe('launchBrowser', () => {
test('Windows: prefers system Chrome via channel:chrome', async () => {
setPlatform('win32');
const p = makePuppeteer();
const browser = await launchBrowser(p.mod, { headless: true, args: ['--foo'] });
expect(browser).toBe(p.fakeBrowser);
expect(p.calls).toHaveLength(1);
expect(p.calls[0].channel).toBe('chrome');
expect(p.calls[0].headless).toBe(true);
expect(p.calls[0].args).toEqual(['--foo']);
});
test('Windows: falls back to bundled when system Chrome is unavailable', async () => {
setPlatform('win32');
const p = makePuppeteer({ failChannel: true });
const browser = await launchBrowser(p.mod, { headless: true, args: [] });
expect(browser).toBe(p.fakeBrowser);
expect(p.calls).toHaveLength(2);
expect(p.calls[0].channel).toBe('chrome'); // first attempt
expect(p.calls[1].channel).toBeUndefined(); // fallback: bundled, no channel
});
test('non-Windows: uses bundled Chrome directly, no channel', async () => {
setPlatform('linux');
const p = makePuppeteer();
const browser = await launchBrowser(p.mod, { headless: true, args: [] });
expect(browser).toBe(p.fakeBrowser);
expect(p.calls).toHaveLength(1);
expect(p.calls[0].channel).toBeUndefined();
});
test('non-Windows: never attempts channel:chrome even if it would succeed', async () => {
setPlatform('darwin');
const p = makePuppeteer();
await launchBrowser(p.mod, {});
expect(p.calls.every(c => c.channel === undefined)).toBe(true);
});
});