Skip to content

Commit fa1cf33

Browse files
committed
Refactor code style and formatting across multiple files
- Removed unnecessary blank lines and adjusted formatting for consistency in various files including JSON, HTML, CSS, and TypeScript. - Improved readability by aligning code structure and ensuring proper indentation. - Updated comments for clarity and consistency in hooks and utility functions.
1 parent 9d83404 commit fa1cf33

24 files changed

Lines changed: 322 additions & 273 deletions

File tree

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
---
22
name: Bug report
33
about: Something doesn't work.
4-
title: "[BUG]"
4+
title: '[BUG]'
55
labels: ''
66
assignees: ''
7-
87
---
98

109
**Describe the bug**
1110
A clear and concise description of what the bug is.
1211

13-
1412
**To Reproduce**
1513
Steps to reproduce the behavior:
14+
1615
1. Go to '...'
1716
2. Click on '....'
1817
3. Scroll down to '....'
@@ -29,5 +28,6 @@ NOTE: You should always try and look for a fix first.
2928
If applicable, add screenshots to help explain your problem.
3029

3130
**Desktop (please complete the following information):**
32-
- OS: [e.g. Windows, Linux, MacOS] including version
33-
- Browser [e.g. chrome, firefox] including version
31+
32+
- OS: [e.g. Windows, Linux, MacOS] including version
33+
- Browser [e.g. chrome, firefox] including version

.github/dependabot.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
version: 2
77
updates:
8-
- package-ecosystem: "npm" # See documentation for possible values
9-
directory: "/" # Location of package manifests
8+
- package-ecosystem: 'npm' # See documentation for possible values
9+
directory: '/' # Location of package manifests
1010
schedule:
11-
interval: "weekly"
11+
interval: 'weekly'

.github/stale.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ markComment: >
1414
recent activity. It will be closed if no further activity occurs. Thank you
1515
for your contributions.
1616
# Comment to post when closing a stale issue. Set to `false` to disable
17-
closeComment: true
17+
closeComment: true

DEBUGGING.md

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,23 @@ The extension now has comprehensive logging throughout all components. This guid
99
### Logger Architecture
1010

1111
All logging uses a centralized logger (`src/lib/logger.ts`) that provides:
12+
1213
- **Colorized output** - Different colors for different contexts
1314
- **Log levels** - debug, info, warn, error
1415
- **Context tagging** - Each module has its own logger context
1516
- **Filtering** - Can filter by log level and context
1617

1718
### Log Contexts
1819

19-
| Context | Color | Purpose |
20-
|---------|-------|---------|
21-
| `background` | 🔴 Red | Background service worker (event capture) |
22-
| `panel` | 🔵 Cyan | DevTools panel UI |
23-
| `devtools` | ⚪ Gray | DevTools registration |
24-
| `storage` | 🟡 Yellow | Zustand store operations |
25-
| `popup` | 🔵 Blue | Extension popup |
26-
| `content` | 🟢 Green | Content script |
27-
| `ui` | 🟣 Purple | UI components |
20+
| Context | Color | Purpose |
21+
| ------------ | --------- | ----------------------------------------- |
22+
| `background` | 🔴 Red | Background service worker (event capture) |
23+
| `panel` | 🔵 Cyan | DevTools panel UI |
24+
| `devtools` | ⚪ Gray | DevTools registration |
25+
| `storage` | 🟡 Yellow | Zustand store operations |
26+
| `popup` | 🔵 Blue | Extension popup |
27+
| `content` | 🟢 Green | Content script |
28+
| `ui` | 🟣 Purple | UI components |
2829

2930
### Key Logging Points
3031

@@ -95,10 +96,11 @@ Current event count in store: X
9596
**Check Console Logs in This Order:**
9697

9798
1. **Background Script Console** (Service Worker):
99+
98100
```
99101
chrome://extensions/ → Analytics X-Ray → "service worker" link
100102
```
101-
103+
102104
✅ Should see:
103105
- `🚀 Background service worker loaded`
104106
- `📡 webRequest listener registered`
@@ -110,7 +112,7 @@ Current event count in store: X
110112
2. **DevTools Panel Console** (Open DevTools within DevTools):
111113
- Right-click in DevTools panel → Inspect
112114
- OR: `Cmd+Option+I` (Mac) / `Ctrl+Shift+I` (Windows) while DevTools is focused
113-
115+
114116
✅ Should see:
115117
- `🔧 DevTools script loading...`
116118
- `🎨 Panel mounted for tab X`
@@ -134,9 +136,10 @@ Current event count in store: X
134136
#### Step 2: Verify Background Storage
135137

136138
In background console:
139+
137140
```javascript
138141
// Check what's stored
139-
chrome.storage.local.get('events', console.log)
142+
chrome.storage.local.get('events', console.log);
140143

141144
// Should show:
142145
// { events: { "123": [ ...array of events... ] } }
@@ -145,6 +148,7 @@ chrome.storage.local.get('events', console.log)
145148
#### Step 3: Verify Panel Initialization
146149

147150
In DevTools panel console (inspect the DevTools panel):
151+
148152
```javascript
149153
// Check if useEventSync is fetching events
150154
// Look for: "📥 Fetching initial events"
@@ -171,34 +175,40 @@ In DevTools panel console (inspect the DevTools panel):
171175
#### 1. Background captures but panel doesn't receive
172176

173177
**Symptoms:**
178+
174179
- Background shows `✅ Captured X event(s)`
175180
- Background shows `⚠️ No listeners for message`
176181
- Panel doesn't update
177182

178183
**Solution:**
184+
179185
- Panel isn't registered to listen for messages
180186
- Check if `useEventSync` hook is being used
181187
- Check if panel console shows `👂 Message listener registered`
182188

183189
#### 2. Different tab IDs
184190

185191
**Symptoms:**
192+
186193
- Background shows events for tab ID `123`
187194
- Panel shows it's listening for tab ID `456`
188195

189196
**Solution:**
197+
190198
- DevTools panel gets `Browser.devtools.inspectedWindow.tabId`
191199
- Make sure you're inspecting the correct tab
192200
- Check panel console: `Inspected tab ID: X`
193201

194202
#### 3. Storage mismatch
195203

196204
**Symptoms:**
205+
197206
- Background stores in `storage.local['events']`
198207
- Panel stores in `storage.local['tab-123']`
199208
- Events never sync
200209

201210
**Solution:**
211+
202212
- This is by design - two separate storage locations
203213
- Background uses `events` for network capture persistence
204214
- Panel uses `tab-X` for Zustand store persistence
@@ -209,30 +219,32 @@ In DevTools panel console (inspect the DevTools panel):
209219
### Enable Only Specific Log Contexts
210220

211221
In any console:
222+
212223
```javascript
213224
// Show only background logs
214-
logger.configure({ enabledContexts: ['background'] })
225+
logger.configure({ enabledContexts: ['background'] });
215226

216227
// Show only panel and storage logs
217-
logger.configure({ enabledContexts: ['panel', 'storage'] })
228+
logger.configure({ enabledContexts: ['panel', 'storage'] });
218229

219230
// Show all logs (default)
220-
logger.configure({ enabledContexts: 'all' })
231+
logger.configure({ enabledContexts: 'all' });
221232
```
222233

223234
### Change Log Level
224235

225236
```javascript
226237
// Only show warnings and errors
227-
logger.configure({ minLevel: 'warn' })
238+
logger.configure({ minLevel: 'warn' });
228239

229240
// Show everything (default)
230-
logger.configure({ minLevel: 'debug' })
241+
logger.configure({ minLevel: 'debug' });
231242
```
232243

233244
### Inspect Store State
234245

235246
In panel console (inspect DevTools):
247+
236248
```javascript
237249
// Get the tab store for current tab
238250
const tabId = chrome.devtools.inspectedWindow.tabId;
@@ -249,18 +261,20 @@ useStore.subscribe(console.log);
249261
### Manually Trigger Event Fetch
250262

251263
In panel console:
264+
252265
```javascript
253266
const tabId = chrome.devtools.inspectedWindow.tabId;
254267
const events = await chrome.runtime.sendMessage({
255268
type: 'GET_EVENTS',
256-
tabId
269+
tabId,
257270
});
258271
console.log('Events from background:', events);
259272
```
260273

261274
## Testing the Fix
262275

263276
1. **Reload extension**:
277+
264278
```
265279
chrome://extensions/ → Reload button
266280
```
@@ -338,4 +352,3 @@ console.log('Events from background:', events);
338352
[analytics-x-ray] [storage] ➕ Adding event to store (tabId: 123): ...
339353
[analytics-x-ray] [panel] 📊 Event count changed: 5
340354
```
341-

LOGGING-SUMMARY.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### 1. Created Centralized Logger (`src/lib/logger.ts`)
66

77
A 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

3436
The 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
113116
4. 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

127131
Good 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

151157
1. With the Analytics X-Ray panel open
152158
2. Right-click anywhere in the panel
153-
3. Click "Inspect"
159+
3. Click "Inspect"
154160
4. 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):
186193
3. 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):
200209
If 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:
208218
If 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

214225
Run in background console:
226+
215227
```javascript
216-
chrome.storage.local.get('events', console.log)
228+
chrome.storage.local.get('events', console.log);
217229
```
218230

219231
Should 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

225238
If "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

232246
If 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

238253
If 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

244260
If 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+
260278
1. Make sure DevTools panel is open
261279
2. Check panel console for `👂 Message listener registered`
262280
3. 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+
269288
1. Check background log: `tabId: XXX`
270289
2. Check panel log: `Inspected tab ID: XXX`
271290
3. 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+
278298
1. Check both consoles side-by-side
279299
2. Verify message is sent (background)
280300
3. Verify message is received (panel)
@@ -300,4 +320,3 @@ If NO → Store may not be connected to UI
300320
6. **Use the debugging guide** to troubleshoot
301321

302322
The logging will tell you exactly where the issue is! 🎯
303-

components.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@
1818
"hooks": "@src/hooks"
1919
}
2020
}
21-

0 commit comments

Comments
 (0)