@@ -154,7 +154,9 @@ function showPendingIcon(tabId) {
154154function notifyPopup ( tabId ) {
155155 const port = popupPorts . get ( tabId ) ;
156156 if ( port ) {
157- port . postMessage ( { type : 'update' , data : tabData . get ( tabId ) || null } ) ;
157+ const data = tabData . get ( tabId ) || null ;
158+ console . log ( '[CF Cache Status] notifyPopup tabId:' , tabId , 'hasData:' , ! ! data ) ;
159+ port . postMessage ( { type : 'update' , data } ) ;
158160 }
159161}
160162
@@ -166,6 +168,7 @@ function notifyPopup(tabId) {
166168
167169browser . webNavigation . onBeforeNavigate . addListener ( ( details ) => {
168170 if ( details . frameId === 0 ) {
171+ console . log ( '[CF Cache Status] onBeforeNavigate tabId:' , details . tabId , 'url:' , details . url ) ;
169172 tabData . delete ( details . tabId ) ;
170173 clearBadge ( details . tabId ) ;
171174 notifyPopup ( details . tabId ) ;
@@ -181,11 +184,14 @@ browser.webNavigation.onBeforeNavigate.addListener((details) => {
181184
182185browser . webNavigation . onCompleted . addListener ( ( details ) => {
183186 if ( details . frameId === 0 ) {
187+ console . log ( '[CF Cache Status] onCompleted tabId:' , details . tabId , 'url:' , details . url ) ;
184188 const data = tabData . get ( details . tabId ) ;
185189 const pending = pendingNavigations . get ( details . tabId ) ;
186190
187191 // Check if we never received headers (Safari limitation with external links/bookmarks)
188192 if ( pending && ! pending . headersReceived ) {
193+ console . log ( '[CF Cache Status] No headers received (Safari limitation)' ) ;
194+
189195 const existingData = tabData . get ( details . tabId ) ;
190196 if ( existingData ) {
191197 existingData . noHeaders = true ;
@@ -223,6 +229,8 @@ browser.webNavigation.onCompleted.addListener((details) => {
223229 * Called by both onHeadersReceived and onResponseStarted (Safari fallback).
224230 */
225231function processMainFrameHeaders ( details ) {
232+ console . log ( '[CF Cache Status] processMainFrameHeaders tabId:' , details . tabId , 'url:' , details . url ) ;
233+
226234 // Mark navigation as having received headers (for Safari limitation detection)
227235 const pendingNav = pendingNavigations . get ( details . tabId ) ;
228236 if ( pendingNav ) {
@@ -241,6 +249,7 @@ function processMainFrameHeaders(details) {
241249 // Detect CDN and parse status
242250 const cdn = detectCDN ( headers ) ;
243251 const status = parseCacheStatus ( headers , cdn ) ;
252+ console . log ( '[CF Cache Status] Detected cdn:' , cdn , 'status:' , status , 'headers:' , Object . keys ( headers ) . join ( ', ' ) ) ;
244253
245254 // Store data
246255 tabData . set ( details . tabId , {
@@ -258,6 +267,7 @@ function processMainFrameHeaders(details) {
258267browser . webRequest . onHeadersReceived . addListener (
259268 ( details ) => {
260269 if ( details . type === 'main_frame' && details . frameId === 0 ) {
270+ console . log ( '[CF Cache Status] onHeadersReceived tabId:' , details . tabId ) ;
261271 processMainFrameHeaders ( details ) ;
262272 }
263273 } ,
@@ -274,6 +284,7 @@ browser.webRequest.onResponseStarted.addListener(
274284
275285 const pendingNav = pendingNavigations . get ( details . tabId ) ;
276286 if ( pendingNav && ! pendingNav . headersReceived ) {
287+ console . log ( '[CF Cache Status] onResponseStarted fallback tabId:' , details . tabId ) ;
277288 processMainFrameHeaders ( details ) ;
278289 }
279290 } ,
@@ -284,13 +295,15 @@ browser.webRequest.onResponseStarted.addListener(
284295// --- Tab Events ---
285296
286297browser . tabs . onRemoved . addListener ( ( tabId ) => {
298+ console . log ( '[CF Cache Status] onRemoved tabId:' , tabId ) ;
287299 tabData . delete ( tabId ) ;
288300 popupPorts . delete ( tabId ) ;
289301 pendingNavigations . delete ( tabId ) ;
290302} ) ;
291303
292304browser . tabs . onActivated . addListener ( ( activeInfo ) => {
293305 const data = tabData . get ( activeInfo . tabId ) ;
306+ console . log ( '[CF Cache Status] onActivated tabId:' , activeInfo . tabId , 'hasData:' , ! ! data , 'status:' , data ?. status ) ;
294307 if ( data ) {
295308 if ( data . noHeaders ) {
296309 showPendingIcon ( activeInfo . tabId ) ;
@@ -350,6 +363,7 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
350363 }
351364
352365 if ( message . type === 'performanceData' && sender . tab ) {
366+ console . log ( '[CF Cache Status] performanceData received tabId:' , sender . tab . id , 'ttfb:' , message . metrics ?. ttfb ) ;
353367 const existing = tabData . get ( sender . tab . id ) ;
354368 if ( existing ) {
355369 existing . performance = message . metrics ;
@@ -372,16 +386,19 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
372386// --- Popup Port Connection ---
373387
374388browser . runtime . onConnect . addListener ( ( port ) => {
389+ console . log ( '[CF Cache Status] onConnect port:' , port . name ) ;
375390 if ( port . name !== 'popup' ) return ;
376391
377392 port . onMessage . addListener ( ( msg ) => {
378393 if ( msg . type === 'subscribe' && msg . tabId ) {
394+ console . log ( '[CF Cache Status] Popup subscribed to tabId:' , msg . tabId ) ;
379395 popupPorts . set ( msg . tabId , port ) ;
380396 port . postMessage ( { type : 'update' , data : tabData . get ( msg . tabId ) || null } ) ;
381397 }
382398 } ) ;
383399
384400 port . onDisconnect . addListener ( ( ) => {
401+ console . log ( '[CF Cache Status] Popup disconnected' ) ;
385402 for ( const [ tabId , p ] of popupPorts ) {
386403 if ( p === port ) {
387404 popupPorts . delete ( tabId ) ;
0 commit comments