@@ -37,6 +37,7 @@ interface ElectronWebview extends HTMLElement { |
37 | 37 | preload?: string; |
38 | 38 | webpreferences?: string; |
39 | 39 | getWebContentsId: () => number; |
| 40 | + getURL: () => string; |
40 | 41 | executeJavaScript: (code: string, userGesture?: boolean) => Promise<unknown>; |
41 | 42 | } |
42 | 43 |
|
@@ -135,8 +136,8 @@ export function HostedBrowserWebview(props: { |
135 | 136 |
|
136 | 137 | const [webviewGeneration, setWebviewGeneration] = useState(0); |
137 | 138 | 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); |
| 139 | + // The guest is transparent until a page's styles apply, so the host paints the theme until then. |
| 140 | + const [readyGeneration, setReadyGeneration] = useState<number | null>(null); |
140 | 141 | const active = presentation.visible && presentation.rect !== null; |
141 | 142 | const shown = active || pictureInPicture; |
142 | 143 | const reportedShown = useEffectEvent(() => serverDriven && shown); |
@@ -188,13 +189,13 @@ export function HostedBrowserWebview(props: { |
188 | 189 | new PointerEvent("pointerdown", { bubbles: true, pointerType: "mouse" }), |
189 | 190 | ); |
190 | 191 | }; |
191 | | - const markCommitted = (event: Event) => { |
192 | | - if ((event as Event & { url?: string }).url === "about:blank") return; |
193 | | - setCommittedGeneration(webviewGeneration); |
| 192 | + const markDocumentReady = () => { |
| 193 | + if (webview.getURL() === "about:blank") return; |
| 194 | + setReadyGeneration(webviewGeneration); |
194 | 195 | }; |
195 | 196 | webview.addEventListener("did-attach", register); |
196 | 197 | webview.addEventListener("dom-ready", register); |
197 | | - webview.addEventListener("did-navigate", markCommitted); |
| 198 | + webview.addEventListener("dom-ready", markDocumentReady); |
198 | 199 | webview.addEventListener("render-process-gone", recoverGuest); |
199 | 200 | webview.addEventListener("focus", dismissHostPopups); |
200 | 201 | register(); |
@@ -203,7 +204,7 @@ export function HostedBrowserWebview(props: { |
203 | 204 | if (recoveryTimeout !== null) clearTimeout(recoveryTimeout); |
204 | 205 | webview.removeEventListener("did-attach", register); |
205 | 206 | webview.removeEventListener("dom-ready", register); |
206 | | - webview.removeEventListener("did-navigate", markCommitted); |
| 207 | + webview.removeEventListener("dom-ready", markDocumentReady); |
207 | 208 | webview.removeEventListener("render-process-gone", recoverGuest); |
208 | 209 | webview.removeEventListener("focus", dismissHostPopups); |
209 | 210 | }; |
@@ -366,7 +367,7 @@ export function HostedBrowserWebview(props: { |
366 | 367 | className={cn( |
367 | 368 | "absolute flex overflow-hidden", |
368 | 369 | // White is the browser canvas behind transparent pages once a document exists. |
369 | | - committedGeneration === webviewGeneration ? "bg-white" : "bg-background", |
| 370 | + readyGeneration === webviewGeneration ? "bg-white" : "bg-background", |
370 | 371 | active && !layout.fillsPanel && "ring-1 ring-border/70 shadow-sm", |
371 | 372 | )} |
372 | 373 | style={{ |
|