Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): desktop-drawn preview snapshots match the page's scale and viewport #19913

MergedScottN-PV(GitHub profile, opens in a new tab)merged 8 commits intomain fromrefs/pull/19913/headmerged by juliusmarminge View on GitHub

Showing 4 changed files with 171 additions and 2 deletions (loading 1).

x
0 of 4 viewed, 4 left
112 additions and 1 deletionapps/server/src/preview/ServerBrowser.test.tsModified
View file
@@ -73,6 +73,14 @@
return frame;
​
+const PNG_HEADER = (() => {
+ const header = Buffer.alloc(24);
+ header.write("IHDR", 12);
+ header.writeUInt32BE(1280, 16);
+ header.writeUInt32BE(800, 20);
+ return header.toString("base64");
+})();
+​
function makeSession(frame?: ReturnType<typeof makeFrame>) {
const events = new NodeEvents.EventEmitter();
return {
@@ -82,7 +90,10 @@
send: vi.fn(async (method: string, input?: unknown): Promise<Record<string, unknown>> => {
if (method === "Page.getNavigationHistory") return { currentIndex: 0, entries: [{}] };
if (method === "Page.getLayoutMetrics") return { cssVisualViewport: { pageX: 0, pageY: 0 } };
- if (method === "Page.captureScreenshot") return { data: "ZnJhbWU=" };
+ if (method === "Page.captureScreenshot") {
+ // A snapshot sizes its screenshot from the PNG header; viewers get JPEG frames as-is.
+ return { data: (input as { format: string }).format === "png" ? PNG_HEADER : "ZnJhbWU=" };
+ }
if (method === "Page.getFrameTree") return { frameTree: { frame: { id: "main" } } };
// Snapshots read password fields from their own isolated world in each frame.
if (method === "Page.createIsolatedWorld") {
@@ -2005,3 +2016,103 @@