Skip to content

Commit 284ce8f

Browse files
authored
fix(desktop): keep PDF preview reloads inside the guest (pingdotgg#21733)
1 parent eb06520 commit 284ce8f

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎apps/desktop/src/preview/GuestInput.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const makeGuest = ({
1919
focusedFrame: focused ? {} : null,
2020
insertText: vi.fn(async () => {}),
2121
sendInputEvent: vi.fn(),
22+
reload: vi.fn(),
23+
reloadIgnoringCache: vi.fn(),
2224
};
2325
return {
2426
webContents,
@@ -34,6 +36,19 @@ const makeGuest = ({
3436
};
3537

3638
describe("preview guest input", () => {
39+
it.each([undefined, false, true])(
40+
"reloads only the guest with ignoreCache=%s",
41+
async (ignoreCache) => {
42+
const guest = makeGuest({ focused: false });
43+
await expect(
44+
guest.send("Page.reload", ignoreCache === undefined ? {} : { ignoreCache }),
45+
).resolves.toEqual({});
46+
expect(guest.webContents.reload).toHaveBeenCalledTimes(ignoreCache ? 0 : 1);
47+
expect(guest.webContents.reloadIgnoringCache).toHaveBeenCalledTimes(ignoreCache ? 1 : 0);
48+
expect(guest.sendCommand).not.toHaveBeenCalled();
49+
},
50+
);
51+
3752
it("types into an unfocused guest's own page, not the app's focused field", async () => {
3853
const guest = makeGuest({ focused: false });
3954
await guest.send("Input.insertText", { text: "pairing-code" });

‎apps/desktop/src/preview/GuestInput.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,19 @@ const evaluate = async (debuggee: Electron.Debugger, expression: string) => {
115115
return reply.result?.value;
116116
};
117117

118-
/** Sends one command to the guest's page, keeping key and text input inside it. */
118+
/** Sends one command to the guest's page, keeping reloads and input inside it. */
119119
export const sendPageCommand = async (
120120
webContents: Electron.WebContents,
121121
debuggee: Electron.Debugger,
122122
method: string,
123123
params: Record<string, unknown>,
124124
): Promise<unknown> => {
125+
// Electron's debugger routes Page.reload on a webview to its embedder window.
126+
if (method === "Page.reload") {
127+
if (params["ignoreCache"] === true) webContents.reloadIgnoringCache();
128+
else webContents.reload();
129+
return {};
130+
}
125131
if (!FOCUS_ROUTED_INPUT.has(method) || webContents.focusedFrame) {
126132
return debuggee.sendCommand(method, params);
127133
}

0 commit comments

Comments
 (0)