@@ -52,6 +52,11 @@ export default class AutofillPasswordImport extends ContentFeature {
5252
5353    #domLoaded; 
5454
55+     #currentLocation; 
56+ 
57+     #isBookmarkModalVisible =  false ; 
58+     #isBookmarkProcessed =  false ; 
59+ 
5560    /** @type  {WeakSet<Element> } */ 
5661    #tappedElements =  new  WeakSet ( ) ; 
5762
@@ -422,8 +427,12 @@ export default class AutofillPasswordImport extends ContentFeature {
422427        } 
423428    } 
424429
425-     handleBookmarkImportPath ( pathname )  { 
430+     async   handleBookmarkImportPath ( pathname )  { 
426431        console . log ( 'DEEP DEBUG autofill-password-import: handleBookmarkImportPath' ,  pathname ) ; 
432+         if  ( pathname  ===  '/'  &&  ! this . #isBookmarkModalVisible)  { 
433+             await  this . clickDisselectAllButton ( ) ; 
434+             await  this . selectBookmark ( ) ; 
435+         } 
427436    } 
428437
429438    /** 
@@ -508,7 +517,95 @@ export default class AutofillPasswordImport extends ContentFeature {
508517        this . #settingsButtonSettings =  this . getFeatureSetting ( 'settingsButton' ) ; 
509518    } 
510519
520+     /** Bookmark import code */ 
521+     get  disselectAllButtonSelector ( )  { 
522+         return  'c-wiz[data-node-index="4;0"] button' ; 
523+     } 
524+ 
525+     get  bookmarkSelectButtonSelector ( )  { 
526+         return  'fieldset.rcetic input' ; 
527+     } 
528+ 
529+     get  chromeSectionSelector ( )  { 
530+         return  'c-wiz [data-id="chrome"]' ; 
531+     } 
532+ 
533+     get  nextStepButtonSelector ( )  { 
534+         return  'div[data-jobid] > div:nth-of-type(2) button' ; 
535+     } 
536+ 
537+     get  createExportButtonSelector ( )  { 
538+         return  'div[data-configure-step] button' ; 
539+     } 
540+ 
541+     async  findDisselectAllButton ( )  { 
542+         return  await  withExponentialBackoff ( ( )  =>  document . querySelectorAll ( this . disselectAllButtonSelector ) [ 1 ] ) ; 
543+     } 
544+     async  selectBookmark ( )  { 
545+         if  ( this . #isBookmarkProcessed)  { 
546+             return ; 
547+         } 
548+         const  chromeDataButtonSelector  =  `${ this . chromeSectionSelector }   button` ; 
549+         const  chromeDataButton  =  /** @type  HTMLButtonElement */  ( 
550+             await  withExponentialBackoff ( ( )  =>  document . querySelectorAll ( chromeDataButtonSelector ) [ 1 ] ,  5 ) 
551+         ) ; 
552+         chromeDataButton ?. focus ( ) ; 
553+         chromeDataButton ?. click ( ) ; 
554+         this . #isBookmarkModalVisible =  true ; 
555+         await  this . domLoaded ; 
556+         const  disselectAllButton  =  /** @type  HTMLButtonElement */  ( 
557+             await  withExponentialBackoff ( ( )  =>  document . querySelectorAll ( 'fieldset.rcetic button' ) [ 1 ] ) 
558+         ) ; 
559+ 
560+         disselectAllButton ?. click ( ) ; 
561+ 
562+         const  bookmarkSelectButton  =  /** @type  HTMLInputElement */  ( 
563+             await  withExponentialBackoff ( ( )  =>  document . querySelectorAll ( this . bookmarkSelectButtonSelector ) [ 1 ] ) 
564+         ) ; 
565+ 
566+         await  withExponentialBackoff ( ( )  =>  ! bookmarkSelectButton ?. checked ) ; 
567+ 
568+         bookmarkSelectButton ?. click ( ) ; 
569+ 
570+         const  okButton  =  /** @type  HTMLButtonElement */  ( document . querySelectorAll ( 'div[role="button"]' ) [ 7 ] ) ; 
571+ 
572+         await  withExponentialBackoff ( ( )  =>  okButton . ariaDisabled  !==  'true' ) ; 
573+         
574+         okButton ?. click ( ) ; 
575+         this . #isBookmarkModalVisible =  false ; 
576+         this . #isBookmarkProcessed =  true ; 
577+ 
578+         const  nextStepButton  =  /** @type  HTMLButtonElement */  ( document . querySelectorAll ( this . nextStepButtonSelector ) [ 0 ] ) ; 
579+         nextStepButton ?. scrollIntoView ( {  behavior : 'smooth' ,  block : 'center' ,  inline : 'center'  } ) ; 
580+         nextStepButton ?. click ( ) ; 
581+ 
582+         const  createExportButton  =  /** @type  HTMLButtonElement */  ( document . querySelectorAll ( this . createExportButtonSelector ) [ 0 ] ) ; 
583+         createExportButton ?. scrollIntoView ( {  behavior : 'smooth' ,  block : 'center' ,  inline : 'center'  } ) ; 
584+         createExportButton ?. click ( ) ; 
585+     } 
586+ 
587+     async  clickDisselectAllButton ( )  { 
588+         const  element  =  /** @type  HTMLButtonElement */  ( await  this . findDisselectAllButton ( ) ) ; 
589+         console . log ( 'Deep element' ,  element ) ; 
590+         if  ( element  !=  null )  { 
591+             element . click ( ) ; 
592+         } 
593+ 
594+         const  chromeSectionElement  =  /** @type  HTMLInputElement */  ( 
595+             await  withExponentialBackoff ( ( )  =>  document . querySelectorAll ( this . chromeSectionSelector ) [ 0 ] . querySelector ( 'input' ) ) 
596+         ) ; 
597+         console . log ( 'DEEP chromeSectionElement' ,  chromeSectionElement ) ; 
598+ 
599+         // First wait for the element to become unchecked (due to slow disselection) 
600+         await  withExponentialBackoff ( ( )  =>  ! chromeSectionElement ?. checked ) ; 
601+ 
602+         chromeSectionElement . scrollIntoView ( {  behavior : 'smooth' ,  block : 'center' ,  inline : 'center'  } ) ; 
603+ 
604+         chromeSectionElement ?. click ( ) ; 
605+     } 
606+ 
511607    urlChanged ( )  { 
608+         console . log ( 'DEEP DEBUG autofill-password-import: urlChanged' ,  window . location ) ; 
512609        this . handleLocation ( window . location ) ; 
513610    } 
514611
0 commit comments