55### 1. Created Centralized Logger (` src/lib/logger.ts ` )
66
77A powerful, colorized logging system with:
8+
89- ** Multiple log levels** : debug, info, warn, error
910- ** Context tagging** : background, panel, devtools, storage, etc.
1011- ** Colorized output** : Different colors for different contexts
@@ -15,6 +16,7 @@ A powerful, colorized logging system with:
1516### 2. Added Logging to Background Script (` src/pages/background/index.ts ` )
1617
1718** Key logs added:**
19+
1820- ✅ Service worker lifecycle (load, init)
1921- ✅ webRequest listener registration with endpoints
2022- ✅ Request interception (detailed flow with collapsible groups)
@@ -32,6 +34,7 @@ A powerful, colorized logging system with:
3234** This was the missing piece!** The panel wasn't syncing with background script.
3335
3436The hook:
37+
3538- Fetches initial events from background on mount
3639- Listens for ` EVENTS_CAPTURED ` messages
3740- Filters events by tab ID
@@ -113,6 +116,7 @@ yarn build:chrome
1131164 . Console will open showing background logs
114117
115118** You should see:**
119+
116120```
117121[analytics-x-ray] [background] 🚀 Background service worker loaded
118122[analytics-x-ray] [background] 🔧 Initializing background script...
@@ -125,10 +129,12 @@ yarn build:chrome
125129### Step 4: Navigate to a Site with Segment
126130
127131Good test sites:
132+
128133- segment.com
129134- Any site using Segment analytics (check Network tab for api.segment.io requests)
130135
131136** Background console should show:**
137+
132138```
133139[analytics-x-ray] [background] 🎯 Request intercepted (tabId: 123)
134140 URL: https://api.segment.io/v1/t
@@ -150,10 +156,11 @@ Good test sites:
150156
1511571 . With the Analytics X-Ray panel open
1521582 . Right-click anywhere in the panel
153- 3 . Click "Inspect"
159+ 3 . Click "Inspect"
1541604 . OR: Press ` Cmd+Option+I ` (Mac) / ` Ctrl+Shift+I ` (Windows) while panel is focused
155161
156162** Panel console should show:**
163+
157164```
158165[analytics-x-ray] [devtools] 🔧 DevTools script loading...
159166[analytics-x-ray] [devtools] Inspected tab ID: 123
@@ -186,11 +193,13 @@ While watching BOTH consoles (background + panel):
1861933 . Interact with the site
187194
188195** Background should show:**
196+
189197- ` 🎯 Request intercepted `
190198- ` ✅ Captured X event(s) `
191199- ` 📤 Sending message `
192200
193201** Panel should show:**
202+
194203- ` 📬 Received EVENTS_CAPTURED message `
195204- ` ✅ Adding X new event(s) to store `
196205- ` 📊 Event count changed `
@@ -200,6 +209,7 @@ While watching BOTH consoles (background + panel):
200209If events don't show:
201210
202211### ✅ Check 1: Background is Capturing
212+
203213- [ ] Open background console
204214- [ ] Navigate to test page
205215- [ ] See ` 🎯 Request intercepted ` logs?
@@ -208,42 +218,49 @@ If events don't show:
208218If NO → Check manifest permissions and webRequest setup
209219
210220### ✅ Check 2: Background is Storing
221+
211222- [ ] Background shows ` 💾 Stored X event(s) ` ?
212223- [ ] Background shows ` 💾 Persisted X event(s) ` ?
213224
214225Run in background console:
226+
215227``` javascript
216- chrome .storage .local .get (' events' , console .log )
228+ chrome .storage .local .get (' events' , console .log );
217229```
218230
219231Should show events object.
220232
221233### ✅ Check 3: Background is Sending Messages
234+
222235- [ ] Background shows ` 📤 Sending EVENTS_CAPTURED message ` ?
223236- [ ] Shows ` ✅ Message delivered ` or ` ⚠️ No listeners ` ?
224237
225238If "No listeners" → Panel isn't open or didn't register listener
226239
227240### ✅ Check 4: Panel is Listening
241+
228242- [ ] Open panel console (inspect the panel)
229243- [ ] See ` 👂 Message listener registered ` ?
230244- [ ] See ` 📬 Received EVENTS_CAPTURED message ` ?
231245
232246If NO → ` useEventSync ` hook may not be running
233247
234248### ✅ Check 5: Panel is Fetching Initial Events
249+
235250- [ ] Panel shows ` 📥 Fetching initial events ` ?
236251- [ ] Shows ` ✅ Received X initial events ` ?
237252
238253If NO → Background message handler may not be responding
239254
240255### ✅ Check 6: Tab IDs Match
256+
241257- [ ] Background: ` tabId: XXX ` in logs
242258- [ ] Panel: ` Inspected tab ID: XXX ` matches?
243259
244260If NO → Inspecting wrong tab or tab ID mismatch
245261
246262### ✅ Check 7: Events Added to Store
263+
247264- [ ] Storage shows ` ➕ Adding event to store ` ?
248265- [ ] Shows ` Total events in store: X ` ?
249266- [ ] Panel shows ` 📊 Event count changed ` ?
@@ -257,6 +274,7 @@ If NO → Store may not be connected to UI
257274** Cause:** Panel isn't open or message listener not registered
258275
259276** Fix:**
277+
2602781 . Make sure DevTools panel is open
2612792 . Check panel console for ` 👂 Message listener registered `
2622803 . If missing, ` useEventSync ` hook may not be running
@@ -266,6 +284,7 @@ If NO → Store may not be connected to UI
266284** Cause:** DevTools inspecting different tab than where events are captured
267285
268286** Fix:**
287+
2692881 . Check background log: ` tabId: XXX `
2702892 . Check panel log: ` Inspected tab ID: XXX `
2712903 . Make sure you're inspecting the correct tab
@@ -275,6 +294,7 @@ If NO → Store may not be connected to UI
275294** Cause:** Message passing broken
276295
277296** Fix:**
297+
2782981 . Check both consoles side-by-side
2792992 . Verify message is sent (background)
2803003 . Verify message is received (panel)
@@ -300,4 +320,3 @@ If NO → Store may not be connected to UI
3003206 . ** Use the debugging guide** to troubleshoot
301321
302322The logging will tell you exactly where the issue is! 🎯
303-
0 commit comments