-
-
Notifications
You must be signed in to change notification settings - Fork 2
feat(app): frame a device capture as the device #368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| "@wdio/devtools-app": minor | ||
| --- | ||
|
|
||
| Frame a capture that came off a device as the device, not as a desktop browser window. A mobile trace rendered inside the desktop chrome — traffic lights, and an address bar reading `unknown`, since a native app has no url — with the phone left as a narrow strip in the middle of a landscape frame. Measured on a 1170x2532 capture: the image used 162 px of a 388 px frame and the remaining ~60% was backdrop. | ||
|
|
||
| The frame is now shaped from the capture's own decoded pixels, and its header states the device instead of drawing window furniture that describes nothing. The capture's pixels are the only workable source: the metadata viewport disagrees with the screenshot on both platforms, since Android reports the window without the navigation bar and iOS reports points, so an older binary on an iPhone 17 reports a 390x844 window for a 402x874 screen. The frame's own header and padding are taken off before fitting and added back after, or the capture area comes out short by them and the image letterboxes inside a frame that was supposed to be its shape. | ||
|
|
||
| Only the screenshot branch is reframed. A mobile *browser* session — Appium driving Chrome on Android — reports a device and also carries a DOM, and that replay is an iframe laid out at its own captured viewport; shaping the frame to a screenshot as well would fight that sizing for the same box, and such a session is a real browser with a real url, so the browser chrome stays honest there. A desktop capture is untouched. | ||
|
|
||
| Reads the `device` field added in #345, and the decoded-size helper added in #344. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| // The player's frame for a capture that came off a device. A native session has | ||
| // no browser window and no url, so the desktop chrome — traffic lights and an | ||
| // address bar reading `unknown` — describes nothing, and a landscape frame | ||
| // leaves a portrait capture as a narrow strip in the middle of it. | ||
| // | ||
| // Kept out of snapshot.ts (already over the file cap) so the geometry is a pure | ||
| // function the specs can measure without a browser. | ||
|
|
||
| import type { DeviceInfo, ImageSize } from '@wdio/devtools-shared' | ||
| import { deviceLabel } from '@wdio/devtools-shared' | ||
| import { html, type nothing, type TemplateResult } from 'lit' | ||
|
|
||
| /** | ||
| * Padding plus border across one axis. Both come out of the size set on a | ||
| * border-box element, so a frame sized without the border hands its capture an | ||
| * area smaller than the one it was fitted for. | ||
| */ | ||
| export function edgeInset( | ||
| style: CSSStyleDeclaration, | ||
| from: 'Left' | 'Top', | ||
| to: 'Right' | 'Bottom' | ||
| ): number { | ||
| const read = (value: string) => parseFloat(value || '0') || 0 | ||
| return ( | ||
| read(style[`padding${from}` as 'paddingLeft']) + | ||
| read(style[`padding${to}` as 'paddingRight']) + | ||
| read(style[`border${from}Width` as 'borderLeftWidth']) + | ||
| read(style[`border${to}Width` as 'borderRightWidth']) | ||
| ) | ||
| } | ||
|
|
||
| /** What the frame spends on itself before the capture gets any room. */ | ||
| export interface FrameChrome { | ||
| /** Height of the frame's header — furniture above the capture. */ | ||
| headerHeight: number | ||
| /** The frame's own horizontal padding and border. */ | ||
| insetX: number | ||
| /** The frame's own vertical padding and border. */ | ||
| insetY: number | ||
| } | ||
|
|
||
| /** | ||
| * Size for a frame holding `capture`, so the frame is the shape of the device | ||
| * rather than of the pane. Derived from the capture's own decoded pixels: the | ||
| * metadata viewport cannot serve, because it disagrees with the screenshot on | ||
| * both mobile platforms — Android reports the window without the navigation | ||
| * bar, and iOS reports points, so an older binary on an iPhone 17 says 390x844 | ||
| * of a 402x874 screen. | ||
| * | ||
| * The frame's own furniture is taken off before fitting and added back after. | ||
| * Fitting the whole frame to the capture instead leaves the capture AREA short | ||
| * by the header and the padding, so the image letterboxes inside a frame that | ||
| * was supposed to be its shape. | ||
| */ | ||
| export function deviceFrameSize( | ||
| pane: { width: number; height: number }, | ||
| capture: ImageSize, | ||
| chrome: FrameChrome | ||
| ): { width: number; height: number } { | ||
| const usableWidth = pane.width - chrome.insetX | ||
| const usableHeight = pane.height - chrome.insetY - chrome.headerHeight | ||
| if ( | ||
| !capture.width || | ||
| !capture.height || | ||
| usableWidth <= 0 || | ||
| usableHeight <= 0 | ||
| ) { | ||
| return { width: pane.width, height: pane.height } | ||
| } | ||
| const scale = Math.min( | ||
| usableWidth / capture.width, | ||
| usableHeight / capture.height | ||
| ) | ||
| return { | ||
| width: Math.round(capture.width * scale) + chrome.insetX, | ||
| height: | ||
| Math.round(capture.height * scale) + chrome.headerHeight + chrome.insetY | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The frame's header for a device capture: what it was recorded on, in place of | ||
| * window furniture that does not apply. Keeps the view-toggle slot, which is | ||
| * how the Snapshot/Screencast switch stays reachable. | ||
| */ | ||
| export function renderDeviceChrome( | ||
| device: DeviceInfo, | ||
| viewToggle: TemplateResult | typeof nothing | ||
| ): TemplateResult { | ||
| return html` | ||
| <header | ||
| class="device-chrome flex items-center mx-2 bg-sideBarBackground rounded-t-[14px]" | ||
| > | ||
| <span class="device-label truncate" title=${deviceLabel(device)} | ||
| >${deviceLabel(device)}</span | ||
| > | ||
| ${viewToggle} | ||
| </header> | ||
| ` | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.