Prefer resident webview for screenshot prep

This commit is contained in:
Mohamed Boudra
2026-07-03 07:50:34 +02:00
parent cda1ba43cc
commit 1bf50349a5
2 changed files with 72 additions and 1 deletions
@@ -92,6 +92,17 @@ function findBrowserWebview(browserId: string, ownerDocument: Document): HTMLEle
return null;
}
function findBrowserWebviewForPixelCapture(
browserId: string,
ownerDocument: Document,
): HTMLElement | null {
const resident = residentWebviewsByBrowserId.get(browserId) ?? null;
if (resident?.isConnected) {
return resident;
}
return findBrowserWebview(browserId, ownerDocument);
}
function applyResidentWebviewStyle(webview: HTMLElement): void {
webview.style.display = "inline-flex";
webview.style.flex = "0 0 auto";
@@ -258,6 +269,9 @@ export function ensureResidentBrowserWebview(input: {
const existing = findBrowserWebview(browserId, ownerDocument);
if (existing) {
if (existing.parentElement?.id === RESIDENT_BROWSER_HOST_ID) {
residentWebviewsByBrowserId.set(browserId, existing);
}
return existing;
}
@@ -314,7 +328,7 @@ export async function prepareResidentBrowserWebviewForPixelCapture(input: {
}
const host = getResidentBrowserHost(ownerDocument);
const webview = findBrowserWebview(browserId, ownerDocument);
const webview = findBrowserWebviewForPixelCapture(browserId, ownerDocument);
if (!webview) {
throw new Error(`Browser webview ${browserId} is not mounted.`);
}