Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(snapshot): draw a minimum size browser window for small snapshots (#37640)

Adam Gastineaud1fdd819e838
diff --git a/packages/trace-viewer/src/ui/snapshotTab.css b/packages/trace-viewer/src/ui/snapshotTab.css
index 926685dc81..b96263a82e 100644
--- a/packages/trace-viewer/src/ui/snapshotTab.css
+++ b/packages/trace-viewer/src/ui/snapshotTab.css
@@ -77,9 +77,16 @@
box-shadow: 0 12px 28px 0 rgba(0,0,0,.2),0 2px 4px 0 rgba(0,0,0,.1);
}
+.snapshot-browser-body {
+ height: calc(100% - var(--browser-frame-header-height));
+
+ /* CSS checkerboard */
+ background: conic-gradient(#eee 25%, #ddd 0 50%, #eee 0 75%, #ddd 0) 0 0 / 40px 40px;
+}
+
.snapshot-switcher {
width: 100%;
- height: calc(100% - var(--browser-frame-header-height));
+ height: 100%;
position: relative;
}
diff --git a/packages/trace-viewer/src/ui/snapshotTab.tsx b/packages/trace-viewer/src/ui/snapshotTab.tsx
index c9c20513e5..2839d9877e 100644
--- a/packages/trace-viewer/src/ui/snapshotTab.tsx
+++ b/packages/trace-viewer/src/ui/snapshotTab.tsx
@@ -195,23 +195,35 @@ const SnapshotWrapper: React.FunctionComponent<React.PropsWithChildren<{
const windowHeaderHeight = 40;
const snapshotContainerSize = {
width: snapshotInfo.viewport.width,
- height: snapshotInfo.viewport.height + windowHeaderHeight,
+ height: snapshotInfo.viewport.height,
};
- const scale = Math.min(measure.width / snapshotContainerSize.width, measure.height / snapshotContainerSize.height, 1);
+ const renderedBrowserFrameSize = {
+ width: Math.max(snapshotContainerSize.width, 480),
+ height: Math.max(snapshotContainerSize.height + windowHeaderHeight, 320),
+ };
+
+ const scale = Math.min(measure.width / renderedBrowserFrameSize.width, measure.height / renderedBrowserFrameSize.height, 1);
const translate = {
- x: (measure.width - snapshotContainerSize.width) / 2,
- y: (measure.height - snapshotContainerSize.height) / 2,
+ x: (measure.width - renderedBrowserFrameSize.width) / 2,
+ y: (measure.height - renderedBrowserFrameSize.height) / 2,
};
return <div ref={ref} className='snapshot-wrapper'>
<div className='snapshot-container' style={{
- width: snapshotContainerSize.width + 'px',
- height: snapshotContainerSize.height + 'px',
+ width: renderedBrowserFrameSize.width + 'px',
+ height: renderedBrowserFrameSize.height + 'px',
transform: `translate(${translate.x}px, ${translate.y}px) scale(${scale})`,
}}>
<BrowserFrame url={snapshotInfo.url} />
- {children}
+ <div className='snapshot-browser-body'>
+ <div style={{
+ width: snapshotContainerSize.width + 'px',
+ height: snapshotContainerSize.height + 'px',
+ }}>
+ {children}
+ </div>
+ </div>
</div>
</div>;
};