@@ -22,6 +22,8 @@ export class GitHubPullRequestController {
2222
2323 private followUpScanTimers : number [ ] = [ ] ;
2424
25+ private bootstrapScanIntervalId : number | null = null ;
26+
2527 private settings : ShowMeTalkSettings = DEFAULT_SETTINGS ;
2628
2729 private currentUrl = window . location . href ;
@@ -39,6 +41,13 @@ export class GitHubPullRequestController {
3941 this . scheduleScan ( ) ;
4042 } ;
4143
44+ private readonly boundHandleVisibilityChange = ( ) : void => {
45+ if ( document . visibilityState === 'visible' ) {
46+ this . scheduleScan ( ) ;
47+ this . startBootstrapScanLoop ( ) ;
48+ }
49+ } ;
50+
4251 private readonly boundHandleClicks = ( event : Event ) : void => {
4352 const target = event . target ;
4453 if ( ! ( target instanceof HTMLElement ) ) {
@@ -77,6 +86,7 @@ export class GitHubPullRequestController {
7786 this . bind ( ) ;
7887 this . scheduleScan ( ) ;
7988 this . queueFollowUpScans ( ) ;
89+ this . startBootstrapScanLoop ( ) ;
8090 }
8191
8292 private bind ( ) : void {
@@ -93,6 +103,7 @@ export class GitHubPullRequestController {
93103 document . addEventListener ( 'turbo:render' , this . boundHandleMutations ) ;
94104 window . addEventListener ( 'popstate' , this . boundHandleMutations ) ;
95105 window . addEventListener ( 'scroll' , this . boundHandleScroll , { passive : true } ) ;
106+ document . addEventListener ( 'visibilitychange' , this . boundHandleVisibilityChange ) ;
96107 chrome . storage . onChanged . addListener ( this . boundHandleStorageChanges ) ;
97108 }
98109
@@ -109,6 +120,7 @@ export class GitHubPullRequestController {
109120 this . currentUrl = window . location . href ;
110121 this . manualOverrides . clear ( ) ;
111122 this . queueFollowUpScans ( ) ;
123+ this . startBootstrapScanLoop ( ) ;
112124 }
113125
114126 private scheduleScan ( force = false ) : void {
@@ -138,6 +150,25 @@ export class GitHubPullRequestController {
138150 ) ;
139151 }
140152
153+ private startBootstrapScanLoop ( ) : void {
154+ if ( this . bootstrapScanIntervalId !== null ) {
155+ window . clearInterval ( this . bootstrapScanIntervalId ) ;
156+ }
157+
158+ const startedAt = Date . now ( ) ;
159+ this . bootstrapScanIntervalId = window . setInterval ( ( ) => {
160+ if ( Date . now ( ) - startedAt > 15_000 ) {
161+ if ( this . bootstrapScanIntervalId !== null ) {
162+ window . clearInterval ( this . bootstrapScanIntervalId ) ;
163+ this . bootstrapScanIntervalId = null ;
164+ }
165+ return ;
166+ }
167+
168+ this . scheduleScan ( ) ;
169+ } , 750 ) ;
170+ }
171+
141172 private scanPage ( ) : void {
142173 const url = new URL ( window . location . href ) ;
143174 if ( ! isPullRequestPage ( url ) || ! this . settings . enabled ) {
0 commit comments