Skip to content

Commit 1105d65

Browse files
committed
Branch rebase
1 parent dc83327 commit 1105d65

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

packages/app/src/components/browser/snapshot.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { consume } from '@lit/context'
55
import { type ComponentChildren, h, render, type VNode } from 'preact'
66
import { customElement, query } from 'lit/decorators.js'
77
import type { SimplifiedVNode } from '../../../../script/types'
8+
import type { CommandLog } from '@wdio/devtools-service/types'
89

910
import {
1011
mutationContext,
@@ -101,6 +102,10 @@ export class DevtoolsBrowser extends Element {
101102
window.addEventListener('app-mutation-select', (ev) =>
102103
this.#renderBrowserState(ev.detail)
103104
)
105+
window.addEventListener(
106+
'show-command',
107+
this.#handleShowCommand as EventListener
108+
)
104109
await this.updateComplete
105110
}
106111

@@ -134,6 +139,31 @@ export class DevtoolsBrowser extends Element {
134139
this.iframe.style.transform = `scale(${scale})`
135140
}
136141

142+
#handleShowCommand = (event: Event) =>
143+
this.#renderCommandScreenshot(
144+
(event as CustomEvent<{ command?: CommandLog }>).detail?.command
145+
)
146+
147+
async #renderCommandScreenshot(command?: CommandLog) {
148+
const screenshot = command?.screenshot
149+
if (!screenshot) {
150+
return
151+
}
152+
153+
if (!this.iframe) {
154+
await this.updateComplete
155+
}
156+
if (!this.iframe) {
157+
return
158+
}
159+
160+
this.iframe.srcdoc = `
161+
<body style="margin:0;background:#111;display:flex;justify-content:center;align-items:flex-start;">
162+
<img src="data:image/png;base64,${screenshot}" style="max-width:100%;height:auto;display:block;" />
163+
</body>
164+
`
165+
}
166+
137167
async #renderNewDocument(doc: SimplifiedVNode, baseUrl: string) {
138168
const root = transform(doc)
139169
const baseTag = h('base', { href: baseUrl })

packages/service/src/session.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ export class SessionCapturer {
102102
timestamp,
103103
callSource: absPath
104104
}
105+
try {
106+
newCommand.screenshot = await browser.takeScreenshot()
107+
} catch (shotErr) {
108+
log.warn(`failed to capture screenshot: ${(shotErr as Error).message}`)
109+
}
105110
this.commandsLog.push(newCommand)
106111
this.sendUpstream('commands', [newCommand])
107112

packages/service/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface CommandLog {
99
error?: Error
1010
timestamp: number
1111
callSource: string
12+
screenshot?: string
1213
}
1314

1415
export enum TraceType {

0 commit comments

Comments
 (0)