Skip to content
TypeScript

fix(desktop): keep PDF preview reloads inside the guest (#21733)

Farès SIONI284ce8fe2ff9
diff --git a/apps/desktop/src/preview/GuestInput.test.ts b/apps/desktop/src/preview/GuestInput.test.ts
index d607b217262..7c7f499bc29 100644
--- a/apps/desktop/src/preview/GuestInput.test.ts
+++ b/apps/desktop/src/preview/GuestInput.test.ts
@@ -19,6 +19,8 @@ const makeGuest = ({
focusedFrame: focused ? {} : null,
insertText: vi.fn(async () => {}),
sendInputEvent: vi.fn(),
+ reload: vi.fn(),
+ reloadIgnoringCache: vi.fn(),
};
return {
webContents,
@@ -34,6 +36,19 @@ const makeGuest = ({
};
describe("preview guest input", () => {
+ it.each([undefined, false, true])(
+ "reloads only the guest with ignoreCache=%s",
+ async (ignoreCache) => {
+ const guest = makeGuest({ focused: false });
+ await expect(
+ guest.send("Page.reload", ignoreCache === undefined ? {} : { ignoreCache }),
+ ).resolves.toEqual({});
+ expect(guest.webContents.reload).toHaveBeenCalledTimes(ignoreCache ? 0 : 1);
+ expect(guest.webContents.reloadIgnoringCache).toHaveBeenCalledTimes(ignoreCache ? 1 : 0);
+ expect(guest.sendCommand).not.toHaveBeenCalled();
+ },
+ );
+
it("types into an unfocused guest's own page, not the app's focused field", async () => {
const guest = makeGuest({ focused: false });
await guest.send("Input.insertText", { text: "pairing-code" });
diff --git a/apps/desktop/src/preview/GuestInput.ts b/apps/desktop/src/preview/GuestInput.ts
index 773d6b79873..35006dfcec0 100644
--- a/apps/desktop/src/preview/GuestInput.ts
+++ b/apps/desktop/src/preview/GuestInput.ts
@@ -115,13 +115,19 @@ const evaluate = async (debuggee: Electron.Debugger, expression: string) => {
return reply.result?.value;
};
-/** Sends one command to the guest's page, keeping key and text input inside it. */
+/** Sends one command to the guest's page, keeping reloads and input inside it. */
export const sendPageCommand = async (
webContents: Electron.WebContents,
debuggee: Electron.Debugger,
method: string,
params: Record<string, unknown>,
): Promise<unknown> => {
+ // Electron's debugger routes Page.reload on a webview to its embedder window.
+ if (method === "Page.reload") {
+ if (params["ignoreCache"] === true) webContents.reloadIgnoringCache();
+ else webContents.reload();
+ return {};
+ }
if (!FOCUS_ROUTED_INPUT.has(method) || webContents.focusedFrame) {
return debuggee.sendCommand(method, params);
}