Skip to content

Commit 09f0827

Browse files
bartTCclaude
andcommitted
Add debug logging to service worker, remove from content script
- Added comprehensive logging to background.js for troubleshooting - Removed console.log from content.js to keep browser console clean 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent fd33084 commit 09f0827

4 files changed

Lines changed: 33 additions & 8 deletions

File tree

CF Cache Status/CF Cache Status Extension/Resources/background.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ function showPendingIcon(tabId) {
154154
function 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

167169
browser.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

182185
browser.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
*/
225231
function 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) {
258267
browser.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

286297
browser.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

292304
browser.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

374388
browser.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);

CF Cache Status/CF Cache Status Extension/content.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,16 @@ if (document.readyState === 'complete') {
8585
*/
8686
function sendColorScheme() {
8787
const isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
88-
console.log('[CF Cache Status] Content script sending colorScheme, isDark:', isDark);
8988
browser.runtime.sendMessage({
9089
type: 'colorScheme',
9190
isDark: isDark
92-
}).catch((e) => {
93-
console.log('[CF Cache Status] Content script colorScheme error:', e.message || e);
94-
});
91+
}).catch(() => {});
9592
}
9693

9794
// Send color scheme on page load
98-
console.log('[CF Cache Status] Content script loaded');
9995
sendColorScheme();
10096

10197
// Listen for color scheme changes (user toggles dark/light mode)
102-
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
103-
console.log('[CF Cache Status] Color scheme changed event, isDark:', e.matches);
98+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
10499
sendColorScheme();
105100
});

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
## [v1.0.2] - 2026-01-11
8+
9+
### Added
10+
- Comprehensive debug logging in service worker for troubleshooting
11+
12+
### Changed
13+
- Removed console logging from content script to keep browser console clean
14+
715
## [v1.0.1] - 2026-01-08
816

917
### Fixed

RELEASE_NOTES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Release Notes
22

3+
## Version 1.0.2
4+
5+
- Added debug logging to service worker for easier troubleshooting
6+
- Content script no longer logs to browser console
7+
38
## Version 1.0.1
49

510
- Fixed: Dark mode toolbar icon now displays correctly when Safari launches in dark mode

0 commit comments

Comments
 (0)