From 8bcd96f5e5c33be998b48b57937e701c8828131f Mon Sep 17 00:00:00 2001 From: Sid Date: Wed, 20 May 2026 10:03:01 +0800 Subject: [PATCH] fix(frames): resolve relative screen= against embedder URL (#2316) Shared device frames serve at /frames/.html and previously assigned the raw ?screen= value to the inner iframe.src. A project-relative value like screen=screens/foo.html resolved against /frames/, producing /frames/screens/foo.html (404), instead of the embedding project's /api/projects/:id/raw/screens/foo.html. The five frame HTML files now resolve relative ?screen= values against document.referrer when present (the embedding project preview), falling back to location.href so standalone /frames/* loads keep working. Absolute and root-relative paths are passed through unchanged. Adds an e2e Vitest spec that evaluates each frame's inline diff --git a/assets/frames/browser-chrome.html b/assets/frames/browser-chrome.html index 6ad76ff26..de4d617e6 100644 --- a/assets/frames/browser-chrome.html +++ b/assets/frames/browser-chrome.html @@ -119,10 +119,15 @@ diff --git a/assets/frames/ipad-pro.html b/assets/frames/ipad-pro.html index 256db5ac8..7db169a4b 100644 --- a/assets/frames/ipad-pro.html +++ b/assets/frames/ipad-pro.html @@ -87,9 +87,13 @@ diff --git a/assets/frames/iphone-15-pro.html b/assets/frames/iphone-15-pro.html index 60963ce4e..f74784bbe 100644 --- a/assets/frames/iphone-15-pro.html +++ b/assets/frames/iphone-15-pro.html @@ -166,9 +166,13 @@ diff --git a/assets/frames/macbook.html b/assets/frames/macbook.html index f94628ff2..107bb5f49 100644 --- a/assets/frames/macbook.html +++ b/assets/frames/macbook.html @@ -126,9 +126,13 @@ diff --git a/e2e/tests/frames/screen-resolution.test.ts b/e2e/tests/frames/screen-resolution.test.ts new file mode 100644 index 000000000..a1ed51d40 --- /dev/null +++ b/e2e/tests/frames/screen-resolution.test.ts @@ -0,0 +1,128 @@ +import { readFileSync } from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import vm from 'node:vm'; + +import { describe, expect, it } from 'vitest'; + +const repoRoot = fileURLToPath(new URL('../../../', import.meta.url)); +const framesDir = path.join(repoRoot, 'assets', 'frames'); + +const FRAME_FILES = [ + 'iphone-15-pro.html', + 'android-pixel.html', + 'ipad-pro.html', + 'macbook.html', + 'browser-chrome.html', +] as const; + +function extractFrameScript(htmlPath: string): string { + const html = readFileSync(htmlPath, 'utf8'); + const matches = html.matchAll(/