@@ -8,6 +8,7 @@ import { customElement, query } from 'lit/decorators.js'
88import { context , type TraceLog } from '../../context.js'
99
1010import '~icons/mdi/world.js'
11+ import '../placeholder.js'
1112
1213const MUTATION_SELECTOR = '__mutation-highlight__'
1314
@@ -38,7 +39,7 @@ export class DevtoolsBrowser extends Element {
3839 #activeUrl = ''
3940
4041 @consume ( { context } )
41- data : TraceLog = { } as TraceLog
42+ data : Partial < TraceLog > = { }
4243
4344 static styles = [ ...Element . styles , css `
4445 :host {
@@ -84,16 +85,17 @@ export class DevtoolsBrowser extends Element {
8485 }
8586
8687 #setIframeSize ( ) {
87- if ( ! this . section || ! this . iframe || ! this . header ) {
88+ const metadata = this . data . metadata
89+ if ( ! this . section || ! this . iframe || ! this . header || ! metadata ) {
8890 return
8991 }
9092
9193 this . section . style . width = 'auto'
9294 this . section . style . height = 'auto'
9395
9496 this . iframe . removeAttribute ( 'style' )
95- const viewportWidth = this . data . metadata . viewport . width
96- const viewportHeight = this . data . metadata . viewport . height
97+ const viewportWidth = metadata . viewport . width
98+ const viewportHeight = metadata . viewport . height
9799 const frameSize = this . getBoundingClientRect ( )
98100 const headerSize = this . header . getBoundingClientRect ( )
99101
@@ -115,9 +117,9 @@ export class DevtoolsBrowser extends Element {
115117 this . iframe . style . transform = `scale(${ scale } )`
116118 }
117119
118- async #renderNewDocument ( doc : SimplifiedVNode ) {
120+ async #renderNewDocument ( doc : SimplifiedVNode , baseUrl : string ) {
119121 const root = transform ( doc )
120- const baseTag = h ( 'base' , { href : this . data . metadata . url } )
122+ const baseTag = h ( 'base' , { href : baseUrl } )
121123 const head : VNode < { } > | undefined = ( root . props . children as VNode [ ] )
122124 . filter ( Boolean )
123125 . find ( ( node ) => node ! . type === 'head' )
@@ -188,7 +190,8 @@ export class DevtoolsBrowser extends Element {
188190
189191 #handleChildListMutation ( mutation : TraceMutation ) {
190192 if ( mutation . addedNodes . length === 1 && ! mutation . target ) {
191- this . #renderNewDocument( mutation . addedNodes [ 0 ] as SimplifiedVNode )
193+ const baseUrl = this . data . metadata ?. url || 'unknown'
194+ this . #renderNewDocument( mutation . addedNodes [ 0 ] as SimplifiedVNode , baseUrl )
192195 return this . #renderVdom( )
193196 }
194197
@@ -251,11 +254,16 @@ export class DevtoolsBrowser extends Element {
251254 }
252255
253256 async #renderBrowserState ( mutationEntry ?: TraceMutation ) {
257+ const mutations = this . data . mutations
258+ if ( ! mutations ) {
259+ return
260+ }
261+
254262 const mutationIndex = mutationEntry
255- ? this . data . mutations . indexOf ( mutationEntry )
263+ ? mutations . indexOf ( mutationEntry )
256264 : 0
257265 this . #vdom = document . createDocumentFragment ( )
258- const rootIndex = this . data . mutations
266+ const rootIndex = mutations
259267 . map ( ( m , i ) => [
260268 // is document loaded
261269 m . addedNodes . length === 1 && Boolean ( m . url ) ,
@@ -266,16 +274,16 @@ export class DevtoolsBrowser extends Element {
266274 . map ( ( [ , i ] ) => i )
267275 . pop ( ) || 0
268276
269- this . #activeUrl = this . data . mutations [ rootIndex ] . url || this . data . metadata . url
277+ this . #activeUrl = mutations [ rootIndex ] . url || this . data . metadata ? .url || 'unknown'
270278 for ( let i = rootIndex ; i <= mutationIndex ; i ++ ) {
271- await this . #handleMutation( this . data . mutations [ i ] ) . catch (
279+ await this . #handleMutation( mutations [ i ] ) . catch (
272280 ( err ) => console . warn ( `Failed to render mutation: ${ err . message } ` ) )
273281 }
274282
275283 /**
276284 * scroll changed element into view
277285 */
278- const mutation = this . data . mutations [ mutationIndex ]
286+ const mutation = mutations [ mutationIndex ]
279287 if ( mutation . target ) {
280288 const el = this . #queryElement( mutation . target )
281289 if ( el ) {
@@ -298,7 +306,10 @@ export class DevtoolsBrowser extends Element {
298306 ${ this . #activeUrl}
299307 </ div >
300308 </ header >
301- < iframe class ="origin-top-left "> </ iframe >
309+ ${ this . data . mutations
310+ ? html `< iframe class ="origin-top-left "> </ iframe > `
311+ : html `< wdio-devtools-placeholder style ="height: 500px "> </ wdio-devtools-placeholder > `
312+ }
302313 </ section >
303314 `
304315 }
0 commit comments