@@ -5,6 +5,7 @@ import { consume } from '@lit/context'
55import { type ComponentChildren , h , render , type VNode } from 'preact'
66import { customElement , query } from 'lit/decorators.js'
77import type { SimplifiedVNode } from '../../../../script/types'
8+ import type { CommandLog } from '@wdio/devtools-service/types'
89
910import {
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 } )
0 commit comments