@@ -9,50 +9,96 @@ import '../placeholder.js'
99const COMPONENT = 'wdio-devtools-network'
1010
1111function formatBytes ( bytes ?: number ) : string {
12- if ( ! bytes || bytes === 0 ) return '-'
12+ if ( ! bytes || bytes === 0 ) {
13+ return '-'
14+ }
1315 const k = 1024
1416 const sizes = [ 'B' , 'KB' , 'MB' , 'GB' ]
1517 const i = Math . floor ( Math . log ( bytes ) / Math . log ( k ) )
1618 const size = bytes / Math . pow ( k , i )
17- return size >= 10 ? `${ size . toFixed ( 0 ) } ${ sizes [ i ] } ` : `${ size . toFixed ( 1 ) } ${ sizes [ i ] } `
19+ return size >= 10
20+ ? `${ size . toFixed ( 0 ) } ${ sizes [ i ] } `
21+ : `${ size . toFixed ( 1 ) } ${ sizes [ i ] } `
1822}
1923
2024function formatTime ( ms ?: number ) : string {
21- if ( ! ms ) return '-'
22- if ( ms < 1 ) return `${ ( ms * 1000 ) . toFixed ( 0 ) } μs`
23- if ( ms < 1000 ) return `${ ms . toFixed ( 0 ) } ms`
25+ if ( ms === undefined || ms === null ) {
26+ return '-'
27+ }
28+ if ( ms < 1 ) {
29+ return `${ ms . toFixed ( 2 ) } ms`
30+ }
31+ if ( ms < 1000 ) {
32+ return `${ ms . toFixed ( 0 ) } ms`
33+ }
2434 return `${ ( ms / 1000 ) . toFixed ( 1 ) } s`
2535}
2636
2737function getStatusClass ( status ?: number ) : string {
28- if ( ! status ) return 'text-gray-500'
29- if ( status >= 200 && status < 300 ) return 'text-green-500'
30- if ( status >= 300 && status < 400 ) return 'text-yellow-500'
31- if ( status >= 400 ) return 'text-red-500'
38+ if ( ! status ) {
39+ return 'text-gray-500'
40+ }
41+ if ( status >= 200 && status < 300 ) {
42+ return 'text-green-500'
43+ }
44+ if ( status >= 300 && status < 400 ) {
45+ return 'text-yellow-500'
46+ }
47+ if ( status >= 400 ) {
48+ return 'text-red-500'
49+ }
3250 return 'text-gray-500'
3351}
3452
3553function getResourceType ( request : NetworkRequest ) : string {
3654 const url = request . url . toLowerCase ( )
37- const contentType = request . responseHeaders ?. [ 'content-type' ] ?. toLowerCase ( ) || ''
55+ const contentType =
56+ request . responseHeaders ?. [ 'content-type' ] ?. toLowerCase ( ) || ''
3857
3958 // Check by content-type first
40- if ( contentType . includes ( 'text/html' ) ) return 'HTML'
41- if ( contentType . includes ( 'text/css' ) ) return 'CSS'
42- if ( contentType . includes ( 'javascript' ) || contentType . includes ( 'ecmascript' ) ) return 'JS'
43- if ( contentType . includes ( 'image/' ) ) return 'Image'
44- if ( contentType . includes ( 'font/' ) || contentType . includes ( 'woff' ) ) return 'Font'
45- if ( contentType . includes ( 'application/json' ) ) return 'Fetch'
59+ if ( contentType . includes ( 'text/html' ) ) {
60+ return 'HTML'
61+ }
62+ if ( contentType . includes ( 'text/css' ) ) {
63+ return 'CSS'
64+ }
65+ if (
66+ contentType . includes ( 'javascript' ) ||
67+ contentType . includes ( 'ecmascript' )
68+ ) {
69+ return 'JS'
70+ }
71+ if ( contentType . includes ( 'image/' ) ) {
72+ return 'Image'
73+ }
74+ if ( contentType . includes ( 'font/' ) || contentType . includes ( 'woff' ) ) {
75+ return 'Font'
76+ }
77+ if ( contentType . includes ( 'application/json' ) ) {
78+ return 'Fetch'
79+ }
4680
4781 // Fallback to URL extension
48- if ( url . endsWith ( '.html' ) || url . endsWith ( '.htm' ) ) return 'HTML'
49- if ( url . endsWith ( '.css' ) ) return 'CSS'
50- if ( url . endsWith ( '.js' ) || url . endsWith ( '.mjs' ) ) return 'JS'
51- if ( url . match ( / \. ( p n g | j p g | j p e g | g i f | s v g | w e b p | i c o ) $ / ) ) return 'Image'
52- if ( url . match ( / \. ( w o f f | w o f f 2 | t t f | e o t | o t f ) $ / ) ) return 'Font'
82+ if ( url . endsWith ( '.html' ) || url . endsWith ( '.htm' ) ) {
83+ return 'HTML'
84+ }
85+ if ( url . endsWith ( '.css' ) ) {
86+ return 'CSS'
87+ }
88+ if ( url . endsWith ( '.js' ) || url . endsWith ( '.mjs' ) ) {
89+ return 'JS'
90+ }
91+ if ( url . match ( / \. ( p n g | j p g | j p e g | g i f | s v g | w e b p | i c o ) $ / ) ) {
92+ return 'Image'
93+ }
94+ if ( url . match ( / \. ( w o f f | w o f f 2 | t t f | e o t | o t f ) $ / ) ) {
95+ return 'Font'
96+ }
5397
5498 // Check by request type
55- if ( request . type === 'fetch' || request . method !== 'GET' ) return 'Fetch'
99+ if ( request . type === 'fetch' || request . method !== 'GET' ) {
100+ return 'Fetch'
101+ }
56102
57103 return 'Other'
58104}
@@ -105,7 +151,10 @@ export class DevtoolsNetwork extends Element {
105151 if ( parentTab ) {
106152 const observer = new MutationObserver ( ( mutations ) => {
107153 mutations . forEach ( ( mutation ) => {
108- if ( mutation . type === 'attributes' && mutation . attributeName === 'active' ) {
154+ if (
155+ mutation . type === 'attributes' &&
156+ mutation . attributeName === 'active'
157+ ) {
109158 // Tab became inactive, clear selection
110159 if ( ! parentTab . hasAttribute ( 'active' ) ) {
111160 this . selectedRequest = undefined
@@ -332,7 +381,9 @@ export class DevtoolsNetwork extends Element {
332381
333382 // Filter by resource type
334383 if ( this . filterType !== 'All' ) {
335- filtered = filtered . filter ( ( req ) => getResourceType ( req ) === this . filterType )
384+ filtered = filtered . filter (
385+ ( req ) => getResourceType ( req ) === this . filterType
386+ )
336387 }
337388
338389 // Filter by search query
@@ -424,12 +475,16 @@ export class DevtoolsNetwork extends Element {
424475 > ${ request . status || ( request . error ? 'ERR' : '-' ) } </ span
425476 >
426477 < span class ="truncate text-muted "
427- > ${ request . responseHeaders ?. [ 'content-type' ] ?. split ( ';' ) [ 0 ] || '-' } </ span
478+ > ${ request . responseHeaders ?. [ 'content-type' ] ?. split (
479+ ';'
480+ ) [ 0 ] || '-' } </ span
428481 >
429482 < span > ${ formatTime ( request . time ) } </ span >
430483 < span > ${ formatBytes ( request . size ) } </ span >
431484 < span class ="text-muted "
432- > ${ request . startTime ? `${ request . startTime . toFixed ( 1 ) } s` : '-' } </ span
485+ > ${ request . startTime
486+ ? `${ request . startTime . toFixed ( 1 ) } s`
487+ : '-' } </ span
433488 >
434489 </ div >
435490 `
@@ -486,17 +541,14 @@ export class DevtoolsNetwork extends Element {
486541 ? html `
487542 < div class ="header-row ">
488543 < span class ="header-key "> Error:</ span >
489- < span class ="header-value text-red-500 "
490- > ${ req . error } </ span
491- >
544+ < span class ="header-value text-red-500 "> ${ req . error } </ span >
492545 </ div >
493546 `
494547 : nothing }
495548 </ div >
496549 </ div >
497550
498- ${ req . requestHeaders &&
499- Object . keys ( req . requestHeaders ) . length > 0
551+ ${ req . requestHeaders && Object . keys ( req . requestHeaders ) . length > 0
500552 ? html `
501553 < div class ="detail-section ">
502554 < div class ="detail-title "> Request Headers</ div >
@@ -523,8 +575,7 @@ export class DevtoolsNetwork extends Element {
523575 </ div >
524576 `
525577 : nothing }
526- ${ req . responseHeaders &&
527- Object . keys ( req . responseHeaders ) . length > 0
578+ ${ req . responseHeaders && Object . keys ( req . responseHeaders ) . length > 0
528579 ? html `
529580 < div class ="detail-section ">
530581 < div class ="detail-title "> Response Headers</ div >
0 commit comments