@@ -74,6 +74,7 @@ class App extends React.Component {
74
74
browserName : null ,
75
75
browserVersion : null ,
76
76
browsingContexts : [ ] ,
77
+ bidiCommand : "" ,
77
78
bidiLog : [ ] ,
78
79
consoleInput : "" ,
79
80
consoleOutput : [ ] ,
@@ -189,8 +190,7 @@ class App extends React.Component {
189
190
...state . networkEntries ,
190
191
{
191
192
contextId : data . params . context ,
192
- id :
193
- data . params . request . request + data . params . redirectCount ,
193
+ id : data . params . request . request + data . params . redirectCount ,
194
194
url : data . params . request . url ,
195
195
redirectCount : data . params . redirectCount ,
196
196
request : data . params . request ,
@@ -227,9 +227,13 @@ class App extends React.Component {
227
227
{ }
228
228
) ;
229
229
230
- // If we connected to an existing session, status `ready` will be false.
230
+ // For Firefox if we connected to an existing session, status `ready` will be false.
231
231
// Only attempt to create a new session if `ready` is true.
232
- const canCreateNewSession = sessionStatusResponse . result . ready ;
232
+ // For Chrome we can not send "session.status" command before starting the session,
233
+ // so the `result` property is going to be `undefined`.
234
+ const canCreateNewSession = sessionStatusResponse . result
235
+ ? sessionStatusResponse . result . ready
236
+ : true ;
233
237
// const { isConnectingToExistingSession } = this.state;
234
238
// if (!canCreateNewSession && !isConnectingToExistingSession) {
235
239
// console.log(
@@ -241,12 +245,9 @@ class App extends React.Component {
241
245
242
246
if ( canCreateNewSession ) {
243
247
console . log ( "Creating a new session" ) ;
244
- const sessionNewResponse = await this . #client. sendCommand (
245
- "session.new" ,
246
- {
247
- capabilities : { } ,
248
- }
249
- ) ;
248
+ const sessionNewResponse = await this . #client. sendCommand ( "session.new" , {
249
+ capabilities : { } ,
250
+ } ) ;
250
251
251
252
// Store the session id
252
253
const { capabilities, sessionId } = sessionNewResponse . result ;
@@ -270,14 +271,14 @@ class App extends React.Component {
270
271
} ) ;
271
272
// Chrome doesn't support network events yet, that's why previous subscribe
272
273
// will fail, and, in this case, we will subscribe again excluding network events.
273
- if ( response . error === ' invalid argument' ) {
274
+ if ( response . error === " invalid argument" ) {
274
275
this . #networkEventsSupported = false ;
275
276
this . #client. sendCommand ( "session.subscribe" , {
276
277
events : [
277
278
"browsingContext.contextCreated" ,
278
279
"browsingContext.domContentLoaded" ,
279
280
"browsingContext.load" ,
280
- "log.entryAdded"
281
+ "log.entryAdded" ,
281
282
] ,
282
283
} ) ;
283
284
}
@@ -366,6 +367,16 @@ class App extends React.Component {
366
367
} ) ;
367
368
} ;
368
369
370
+ sendCommand = ( e ) => {
371
+ e . preventDefault ( ) ;
372
+ try {
373
+ const commandObject = JSON . parse ( this . state . bidiCommand ) ;
374
+ this . #client. sendCommand ( commandObject . method , commandObject . params ) ;
375
+ } catch ( error ) {
376
+ console . error ( { error } ) ;
377
+ }
378
+ } ;
379
+
369
380
setActiveTab = ( tab ) => {
370
381
this . setState ( {
371
382
activeTab : tab ,
@@ -449,6 +460,7 @@ class App extends React.Component {
449
460
render ( ) {
450
461
const {
451
462
activeTab,
463
+ bidiCommand,
452
464
bidiLog,
453
465
browserName,
454
466
browserVersion,
@@ -465,29 +477,29 @@ class App extends React.Component {
465
477
pageTimings,
466
478
} = this . state ;
467
479
468
- const tabs = [ {
469
- id : "console" ,
470
- icon : consoleIcon ,
471
- title : "Console" ,
472
- content : (
473
- < Console
474
- consoleOutput = { consoleOutput }
475
- consoleInput = { consoleInput }
476
- isClientReady = { isClientReady }
477
- onSubmit = { this . onConsoleSubmit }
478
- onChange = { this . onInputChange }
479
- evaluationBrowsingContextId = { evaluationBrowsingContextId }
480
- filteringBrowsingContextId = { filteringBrowsingContextId }
481
- browsingContexts = { browsingContexts }
482
- setEvaluationBrowsingContext = {
483
- this . setEvaluationBrowsingContext
484
- }
485
- />
486
- ) ,
487
- } ] ;
480
+ const tabs = [
481
+ {
482
+ id : "console" ,
483
+ icon : consoleIcon ,
484
+ title : "Console" ,
485
+ content : (
486
+ < Console
487
+ consoleOutput = { consoleOutput }
488
+ consoleInput = { consoleInput }
489
+ isClientReady = { isClientReady }
490
+ onSubmit = { this . onConsoleSubmit }
491
+ onChange = { this . onInputChange }
492
+ evaluationBrowsingContextId = { evaluationBrowsingContextId }
493
+ filteringBrowsingContextId = { filteringBrowsingContextId }
494
+ browsingContexts = { browsingContexts }
495
+ setEvaluationBrowsingContext = { this . setEvaluationBrowsingContext }
496
+ />
497
+ ) ,
498
+ } ,
499
+ ] ;
488
500
489
501
// Add network tab only if network events are supported.
490
- if ( this . #networkEventsSupported) {
502
+ if ( this . #networkEventsSupported) {
491
503
tabs . push ( {
492
504
id : "network" ,
493
505
icon : networkIcon ,
@@ -509,8 +521,15 @@ class App extends React.Component {
509
521
tabs . push ( {
510
522
id : "bidi-log" ,
511
523
icon : bidiLogIcon ,
512
- title : "BiDi log" ,
513
- content : < BiDiLog log = { bidiLog } /> ,
524
+ title : "BiDi interface" ,
525
+ content : (
526
+ < BiDiLog
527
+ log = { bidiLog }
528
+ bidiCommand = { bidiCommand }
529
+ onBidiCommandChange = { this . onInputChange }
530
+ sendCommand = { this . sendCommand }
531
+ />
532
+ ) ,
514
533
} ) ;
515
534
516
535
return (
0 commit comments