@@ -32,15 +32,14 @@ const pruneAxTree = (axTree) => {
32
32
properties,
33
33
} = node ;
34
34
35
- if ( ! name ) {
36
- if ( ignored ) {
37
- name = { value : `ignored node: ${ ignoredReasons [ 0 ] . name } ` } ;
38
- }
39
- else {
40
- name = { value : 'visible node with no name' } ;
35
+ if ( ! name ) {
36
+ if ( ignored ) {
37
+ name = { value : `ignored node: ${ ignoredReasons [ 0 ] . name } ` } ;
38
+ } else {
39
+ name = { value : 'visible node with no name' } ;
41
40
}
42
41
}
43
- if ( ! name . value ) {
42
+ if ( ! name . value ) {
44
43
name . value = 'visible node with no name' ;
45
44
}
46
45
const axNode = {
@@ -109,6 +108,24 @@ async function axRecord(tabId) {
109
108
}
110
109
}
111
110
111
+ async function replaceEmptySnap ( tabsObj , tabId , toggleAxRecord ) {
112
+ console . log (
113
+ 'background.js: top of replaceEmptySnap: tabsObj[tabId]:' ,
114
+ JSON . parse ( JSON . stringify ( tabsObj [ tabId ] ) ) ,
115
+ ) ;
116
+ if ( tabsObj [ tabId ] . currLocation . axSnapshot === 'emptyAxSnap' && toggleAxRecord === true ) {
117
+ // add new ax snapshot to currlocation
118
+ const addedAxSnap = await axRecord ( tabId ) ;
119
+ tabsObj [ tabId ] . currLocation . axSnapshot = addedAxSnap ;
120
+ // modify array to include the new recorded ax snapshot
121
+ tabsObj [ tabId ] . axSnapshots [ tabsObj [ tabId ] . currLocation . index ] = addedAxSnap ;
122
+ }
123
+ console . log (
124
+ 'background.js: bottom of replaceEmptySnap: tabsObj[tabId]:' ,
125
+ JSON . parse ( JSON . stringify ( tabsObj [ tabId ] ) ) ,
126
+ ) ;
127
+ }
128
+
112
129
// This function will create the first instance of the test app's tabs object
113
130
// which will hold test app's snapshots, link fiber tree info, chrome tab info, etc.
114
131
function createTabObj ( title ) {
@@ -296,7 +313,7 @@ chrome.runtime.onConnect.addListener((port) => {
296
313
// INCOMING MESSAGE FROM FRONTEND (MainContainer) TO BACKGROUND.js
297
314
// listen for message containing a snapshot from devtools and send it to contentScript -
298
315
// (i.e. they're all related to the button actions on Reactime)
299
- port . onMessage . addListener ( ( msg ) => {
316
+ port . onMessage . addListener ( async ( msg ) => {
300
317
// msg is action denoting a time jump in devtools
301
318
// ---------------------------------------------------------------
302
319
// message incoming from devTools should look like this:
@@ -372,7 +389,22 @@ chrome.runtime.onConnect.addListener((port) => {
372
389
373
390
case 'toggleAxRecord' :
374
391
toggleAxRecord = ! toggleAxRecord ;
375
- return true ;
392
+
393
+ await replaceEmptySnap ( tabsObj , tabId , toggleAxRecord ) ;
394
+
395
+ // sends new tabs obj to devtools
396
+ if ( portsArr . length > 0 ) {
397
+ portsArr . forEach ( ( bg ) =>
398
+ bg . postMessage ( {
399
+ action : 'sendSnapshots' ,
400
+ payload : tabsObj ,
401
+ tabId,
402
+ } ) ,
403
+ ) ;
404
+ } else {
405
+ console . log ( 'background.js: portsArr.length < 0' ) ;
406
+ }
407
+ return true ; // return true so that port remains open
376
408
377
409
case 'reinitialize' :
378
410
chrome . tabs . sendMessage ( tabId , msg ) ;
@@ -424,16 +456,32 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
424
456
break ;
425
457
}
426
458
case 'jumpToSnap' : {
459
+ console . log (
460
+ 'background.js: top of jumpToSnap: tabsObj[tabId]:' ,
461
+ JSON . parse ( JSON . stringify ( tabsObj [ tabId ] ) ) ,
462
+ ) ;
427
463
changeCurrLocation ( tabsObj [ tabId ] , tabsObj [ tabId ] . hierarchy , index , name ) ;
428
464
// hack to test without message from mainSlice
429
- toggleAxRecord = true ;
465
+ // toggleAxRecord = true;
430
466
// record ax tree snapshot of the state that has now been jumped to if user did not toggle button on
431
- if ( tabsObj [ tabId ] . currLocation . axSnapshot === 'emptyAxSnap' && toggleAxRecord === true ) {
432
- // add new ax snapshot to currlocation
433
- const addedAxSnap = await axRecord ( tabId ) ;
434
- tabsObj [ tabId ] . currLocation . axSnapshot = addedAxSnap ;
435
- // modify array to include the new recorded ax snapshot
436
- tabsObj [ tabId ] . axSnapshots [ tabsObj [ tabId ] . currLocation . index ] = addedAxSnap ;
467
+ await replaceEmptySnap ( tabsObj , tabId , toggleAxRecord ) ;
468
+
469
+ console . log (
470
+ 'background.js: bottom of jumpToSnap: tabsObj[tabId]:' ,
471
+ JSON . parse ( JSON . stringify ( tabsObj [ tabId ] ) ) ,
472
+ ) ;
473
+
474
+ // sends new tabs obj to devtools
475
+ if ( portsArr . length > 0 ) {
476
+ portsArr . forEach ( ( bg ) =>
477
+ bg . postMessage ( {
478
+ action : 'sendSnapshots' ,
479
+ payload : tabsObj ,
480
+ tabId,
481
+ } ) ,
482
+ ) ;
483
+ } else {
484
+ console . log ( 'background.js: portsArr.length < 0' ) ;
437
485
}
438
486
439
487
if ( portsArr . length > 0 ) {
@@ -496,6 +544,8 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
496
544
JSON . parse ( JSON . stringify ( tabsObj [ tabId ] ) ) ,
497
545
) ;
498
546
547
+ console . log ( 'background.js: recordSnap case: toggleAxRecord:' , toggleAxRecord ) ;
548
+
499
549
const sourceTab = tabId ;
500
550
tabsObj [ tabId ] . webMetrics = metrics ;
501
551
0 commit comments