@@ -135,6 +135,8 @@ export function HostedBrowserWebview(props: { |
135 | 135 |
|
136 | 136 | const [webviewGeneration, setWebviewGeneration] = useState(0); |
137 | 137 | const [recoverySrc, setRecoverySrc] = useState(initialSrc); |
| 138 | + // A guest with no document is transparent, so the host paints the panel until the first commit. |
| 139 | + const [committedGeneration, setCommittedGeneration] = useState<number | null>(null); |
138 | 140 | const active = presentation.visible && presentation.rect !== null; |
139 | 141 | const shown = active || pictureInPicture; |
140 | 142 | const reportedShown = useEffectEvent(() => serverDriven && shown); |
@@ -186,8 +188,13 @@ export function HostedBrowserWebview(props: { |
186 | 188 | new PointerEvent("pointerdown", { bubbles: true, pointerType: "mouse" }), |
187 | 189 | ); |
188 | 190 | }; |
| 191 | + const markCommitted = (event: Event) => { |
| 192 | + if ((event as Event & { url?: string }).url === "about:blank") return; |
| 193 | + setCommittedGeneration(webviewGeneration); |
| 194 | + }; |
189 | 195 | webview.addEventListener("did-attach", register); |
190 | 196 | webview.addEventListener("dom-ready", register); |
| 197 | + webview.addEventListener("did-navigate", markCommitted); |
191 | 198 | webview.addEventListener("render-process-gone", recoverGuest); |
192 | 199 | webview.addEventListener("focus", dismissHostPopups); |
193 | 200 | register(); |
@@ -196,16 +203,11 @@ export function HostedBrowserWebview(props: { |
196 | 203 | if (recoveryTimeout !== null) clearTimeout(recoveryTimeout); |
197 | 204 | webview.removeEventListener("did-attach", register); |
198 | 205 | webview.removeEventListener("dom-ready", register); |
| 206 | + webview.removeEventListener("did-navigate", markCommitted); |
199 | 207 | webview.removeEventListener("render-process-gone", recoverGuest); |
200 | 208 | webview.removeEventListener("focus", dismissHostPopups); |
201 | 209 | }; |
202 | | - }, [ |
203 | | - clientSettingsHydrated, |
204 | | - config, |
205 | | - runtimeTabId, |
206 | | - // oxlint-disable-next-line react/exhaustive-effect-dependencies -- A crash recovery remounts the webview under a new key, so the listeners attach to the new element. |
207 | | - webviewGeneration, |
208 | | - ]); |
| 210 | + }, [clientSettingsHydrated, config, runtimeTabId, webviewGeneration]); |
209 | 211 |
|
210 | 212 | const lastRect = presentation.rect; |
211 | 213 | const layoutZoomFactor = useBrowserLayoutZoomFactor(zoomFactor); |
@@ -362,7 +364,9 @@ export function HostedBrowserWebview(props: { |
362 | 364 | } |
363 | 365 | aria-hidden={active ? undefined : true} |
364 | 366 | className={cn( |
365 | | - "absolute flex overflow-hidden bg-white", |
| 367 | + "absolute flex overflow-hidden", |
| 368 | + // White is the browser canvas behind transparent pages once a document exists. |
| 369 | + committedGeneration === webviewGeneration ? "bg-white" : "bg-background", |
366 | 370 | active && !layout.fillsPanel && "ring-1 ring-border/70 shadow-sm", |
367 | 371 | )} |
368 | 372 | style={{ |
|