@@ -114,7 +114,7 @@ const RepostConfirmationCancelerTalkClient = {
114114 return false ;
115115 } ,
116116
117- handleURL ( config , url ) {
117+ handleURL ( config , url , callbackWhenMatch ) {
118118 if ( ! url ) {
119119 console . log ( `* Empty URL found` ) ;
120120 return false ;
@@ -135,7 +135,7 @@ const RepostConfirmationCancelerTalkClient = {
135135 console . log ( `handleURL: check for section ${ section . Name } (${ JSON . stringify ( section ) } )` ) ;
136136 if ( this . match ( section , urlToMatch ) ) {
137137 console . log ( ` => unmatched` ) ;
138- this . startMonitoring ( ) ;
138+ callbackWhenMatch ( ) ;
139139 return true ;
140140 }
141141 else {
@@ -153,7 +153,7 @@ const RepostConfirmationCancelerTalkClient = {
153153 for ( const tab of tabs ) {
154154 const url = tab . url ?? tab . pendingUrl ;
155155 console . log ( `handleAllTabs ${ url } (tab=${ tab . id } )` ) ;
156- if ( this . handleURL ( config , url ) ) {
156+ if ( this . handleURL ( config , url , this . startMonitoring ) ) {
157157 break ;
158158 }
159159 } ;
@@ -169,15 +169,40 @@ const RepostConfirmationCancelerTalkClient = {
169169
170170 const config = this . cached ;
171171 const url = tab . pendingUrl || tab . url ;
172- this . handleURL ( config , url ) ;
172+ this . handleURL ( config , url , this . startMonitoring ) ;
173173 } ,
174174
175175 onNavigationCommitted ( details ) {
176176 const url = details . url ;
177177 console . log ( `onNavigationCommitted: ${ url } ` ) ;
178178 const config = this . cached ;
179- this . handleURL ( config , url ) ;
179+ this . handleURL ( config , url , this . startMonitoring ) ;
180180 } ,
181+
182+ onErrorOccurred ( details ) {
183+ console . log ( 'onErrorOccurred:' , details ) ;
184+ if ( details . error === 'net::ERR_CACHE_MISS' ) {
185+ const url = details . url ;
186+ const config = this . cached ;
187+ const tabId = details . tabId ;
188+ this . handleURL ( config , url , ( ) => {
189+ this . closeTab ( tabId ) ;
190+ } ) ;
191+ }
192+ } ,
193+
194+ closeTab ( tabId ) {
195+ if ( tabId !== - 1 ) {
196+ console . log ( "Closing tab:" , tabId ) ;
197+ chrome . tabs . remove ( tabId , ( ) => {
198+ if ( chrome . runtime . lastError ) {
199+ console . log ( "Error while closing tab:" , chrome . runtime . lastError . message )
200+ } else {
201+ console . log ( "Tab closed" ) ;
202+ }
203+ } ) ;
204+ }
205+ }
181206} ;
182207
183208/* Refresh config for every N minute */
@@ -192,6 +217,11 @@ chrome.alarms.onAlarm.addListener((alarm) => {
192217 }
193218} ) ;
194219
220+ chrome . webRequest . onErrorOccurred . addListener (
221+ RepostConfirmationCancelerTalkClient . onErrorOccurred . bind ( RepostConfirmationCancelerTalkClient ) ,
222+ { urls : [ "<all_urls>" ] }
223+ ) ;
224+
195225/* Tab book-keeping for intelligent tab handlings */
196226chrome . tabs . onUpdated . addListener ( RepostConfirmationCancelerTalkClient . onTabUpdated . bind ( RepostConfirmationCancelerTalkClient ) ) ;
197227chrome . webNavigation . onCommitted . addListener ( RepostConfirmationCancelerTalkClient . onNavigationCommitted . bind ( RepostConfirmationCancelerTalkClient ) ) ;
0 commit comments