Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/app/src/components/browser/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { consume } from '@lit/context'
import { type ComponentChildren, h, render, type VNode } from 'preact'
import { customElement, query } from 'lit/decorators.js'
import type { SimplifiedVNode } from '../../../../script/types'
import type { CommandLog } from '@wdio/devtools-service/types'

import {
mutationContext,
Expand Down Expand Up @@ -101,6 +102,10 @@ export class DevtoolsBrowser extends Element {
window.addEventListener('app-mutation-select', (ev) =>
this.#renderBrowserState(ev.detail)
)
window.addEventListener(
'show-command',
this.#handleShowCommand as EventListener
)
await this.updateComplete
}

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

#handleShowCommand = (event: Event) =>
this.#renderCommandScreenshot(
(event as CustomEvent<{ command?: CommandLog }>).detail?.command
)

async #renderCommandScreenshot(command?: CommandLog) {
const screenshot = command?.screenshot
if (!screenshot) {
return
}

if (!this.iframe) {
await this.updateComplete
}
if (!this.iframe) {
return
}

this.iframe.srcdoc = `
<body style="margin:0;background:#111;display:flex;justify-content:center;align-items:flex-start;">
<img src="data:image/png;base64,${screenshot}" style="max-width:100%;height:auto;display:block;" />
</body>
`
}

async #renderNewDocument(doc: SimplifiedVNode, baseUrl: string) {
const root = transform(doc)
const baseTag = h('base', { href: baseUrl })
Expand Down
5 changes: 5 additions & 0 deletions packages/service/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ export class SessionCapturer {
timestamp,
callSource: absPath
}
try {
newCommand.screenshot = await browser.takeScreenshot()
} catch (shotErr) {
log.warn(`failed to capture screenshot: ${(shotErr as Error).message}`)
}
this.commandsLog.push(newCommand)
this.sendUpstream('commands', [newCommand])

Expand Down
1 change: 1 addition & 0 deletions packages/service/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface CommandLog {
error?: Error
timestamp: number
callSource: string
screenshot?: string
}

export enum TraceType {
Expand Down