Skip to content
Merged
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
36 changes: 22 additions & 14 deletions packages/webui/test/browser/real-browser-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,12 @@ export async function launchWithExtension(
}> {
const profileDir = await mkdtemp(join(tmpdir(), "webui-bridge-real-"));
const dist = options.dist ?? extensionDist;
const context = await bounded(
`the ${channel} browser did not start`,
BROWSER_LAUNCH_BOUND_MS,
chromium.launchPersistentContext(profileDir, {
let context: BrowserContext | undefined;
try {
// Give Playwright the launch budget so a timeout aborts its own launch
// and reports the browser logs. Racing the promise only abandoned it.
context = await chromium.launchPersistentContext(profileDir, {
timeout: BROWSER_LAUNCH_BOUND_MS,
headless: true,
// "chromium" is the bundled browser and "msedge" is the installed Edge.
// The extension is one package for both, and the only thing that differs
Expand All @@ -185,17 +187,23 @@ export async function launchWithExtension(
"--no-first-run",
"--no-default-browser-check",
],
}),
);
let worker = context.serviceWorkers()[0];
if (!worker) {
worker = await bounded(
`the ${channel} browser did not start the extension's service worker`,
BROWSER_LAUNCH_BOUND_MS,
context.waitForEvent("serviceworker", { timeout: 30_000 }),
);
});
let worker = context.serviceWorkers()[0];
if (!worker) {
worker = await bounded(
`the ${channel} browser did not start the extension's service worker`,
BROWSER_LAUNCH_BOUND_MS,
context.waitForEvent("serviceworker", { timeout: 30_000 }),
);
}
return { context, worker, extensionId: extensionIdOf(worker), profileDir };
} catch (error) {
// The caller cannot close a browser or profile it never received.
if (context) await closeBrowser(context).catch(() => undefined);
await rm(profileDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 })
.catch(() => undefined);
throw error;
}
return { context, worker, extensionId: extensionIdOf(worker), profileDir };
}

/**
Expand Down
Loading