- Replace token-based auth with HTTP Basic Authentication per Binect API v1 spec - Improve PDF detection: check current tab first, then background service, fallback to recent downloads - Add password visibility toggle in login form - Add extensive debug logging throughout for troubleshooting - Update manifest with alarms, activeTab permissions and <all_urls> host permission - Add documentation files and development helper scripts - Add Binect API specs for reference Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
7.4 KiB
Development & Test-Fix Workflow for BinectChrome
This guide explains how to set up an efficient development workflow for testing and debugging the Chrome extension.
Quick Start
1. Development Mode (Auto-rebuild on changes)
npm run dev
This starts webpack in watch mode - any changes to source files will automatically rebuild the extension.
2. Load Extension in Chrome
Initial Load:
- Open Chrome and navigate to
chrome://extensions/ - Enable "Developer mode" (toggle in top-right corner)
- Click "Load unpacked"
- Select the
/home/worsch/binect-chrome/distdirectory - Note the extension ID (you'll need this for debugging)
Reload After Changes:
- Option A (Manual): Click the reload icon on the extension card at
chrome://extensions/ - Option B (Shortcut): Click the extensions icon in Chrome toolbar → Manage Extensions → Reload
- Option C (Recommended for service worker): Navigate to
chrome://serviceworker-internals/and click "Stop" then reload
3. Debug Service Worker
View Service Worker Logs:
- Go to
chrome://extensions/ - Find your extension
- Click "service worker" link (under "Inspect views")
- This opens DevTools for the service worker
Alternative Method:
- Go to
chrome://serviceworker-internals/ - Find "chrome-extension://[your-extension-id]"
- Click "Inspect" to open DevTools
View Service Worker Status:
chrome://serviceworker-internals/- Shows all service workers, their status, and errors
4. Debug Popup & UI
Popup DevTools:
- Click the extension icon to open the popup
- Right-click inside the popup → "Inspect"
- This opens DevTools for the popup
Tracking Page DevTools:
- Open the tracking page from the popup
- Right-click → "Inspect"
Complete Test-Fix Loop
Workflow Pattern
┌─────────────────────────────────────────────────┐
│ 1. Make code changes in src/ │
│ 2. Webpack auto-rebuilds (if using npm run dev)│
│ 3. Reload extension in Chrome │
│ 4. Check DevTools for errors │
│ 5. Test functionality │
│ 6. Repeat from step 1 │
└─────────────────────────────────────────────────┘
Detailed Steps
-
Start Development Mode
npm run dev -
Make Your Changes
- Edit files in
src/ - Webpack will automatically rebuild
- Edit files in
-
Reload Extension
- Go to
chrome://extensions/ - Click reload icon on BinectChrome card
- For service worker changes: Go to
chrome://serviceworker-internals/→ Stop → Reload
- Go to
-
Check for Errors
- Service Worker: Click "service worker" link or check
chrome://serviceworker-internals/ - Popup: Right-click popup → Inspect
- Console Errors: Check the browser console in all DevTools windows
- Service Worker: Click "service worker" link or check
-
Test Functionality
- Download a PDF to test detection
- Check badge updates
- Test sending PDFs
- Verify tracking data
-
Common Debugging Points
- Service worker errors: Usually permissions or API usage issues
- PDF detection not working: Check Downloads API events
- Badge not updating: Check service worker is running
- Alarms not firing: Check
chrome://serviceworker-internals/for service worker lifecycle
Common Issues & Solutions
Issue: Service Worker Registration Failed (Status Code 15)
Cause: Webpack output format doesn't match manifest type Solution: Ensure webpack.config.js has:
output: {
module: true,
environment: { module: true }
},
experiments: {
outputModule: true
}
Issue: "Cannot read properties of undefined (reading 'onAlarm')"
Cause: Missing "alarms" permission Solution: Add to manifest.json:
"permissions": ["downloads", "storage", "alarms"]
Issue: Service Worker Stops Running
Cause: Chrome stops inactive service workers after 30 seconds (Manifest V3 behavior) Solution: This is normal! Service workers wake up on events (downloads, alarms, messages)
Issue: Changes Not Reflecting
Cause: Extension not reloaded, or cached service worker Solution:
- Always reload after rebuilding
- For stubborn issues: Stop service worker at
chrome://serviceworker-internals/ - Hard reload: Remove extension and re-add it
Testing Specific Features
Test PDF Detection
- Ensure extension is loaded and service worker is running
- Download any PDF file from the web
- Check service worker console for "PDF detected:" log
- Verify badge shows "1"
- Open popup and verify PDF info is displayed
Test Credential Management
- Open popup
- Enter credentials
- Check Chrome DevTools → Application → Storage → Extension Storage
- Verify credentials are encrypted
- Test credential expiry by manipulating storage
Test Alarm/Expiry Check
- Open
chrome://serviceworker-internals/ - Check for alarm registration
- Or use:
chrome.alarms.getAll(console.log)in service worker console
Production Build & Testing
# Build for production
npm run build
# Build is in dist/ directory
# Test the production build by loading dist/ as unpacked extension
Running Unit Tests
# Run tests once
npm test
# Run tests in watch mode
npm run test:watch
# Type checking
npm run type-check
# Linting
npm run lint
npm run lint:fix
Useful Chrome URLs for Extension Development
chrome://extensions/- Manage extensionschrome://serviceworker-internals/- Debug service workerschrome://inspect/#service-workers- Inspect active service workerschrome://downloads/- View downloads (for testing PDF detection)chrome://version/- Check Chrome version
Debugging Tips
- Console.log is your friend: Add logs liberally in development
- Breakpoints: Use debugger; statements or set breakpoints in DevTools
- Storage inspection: Check Application → Storage → Extension Storage in DevTools
- Network tab: Monitor API calls to Binect
- Performance: Use Performance tab to check service worker lifecycle
- Memory: Watch for memory leaks in long-running service workers
VS Code Integration (Optional)
Add to .vscode/launch.json for debugging:
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Debug Extension",
"url": "chrome://extensions/",
"webRoot": "${workspaceFolder}/dist"
}
]
}
Quick Reference Commands
# Development
npm run dev # Watch mode with auto-rebuild
npm run build # Production build
npm test # Run tests
npm run lint # Check code quality
npm run type-check # TypeScript validation
# Chrome URLs
chrome://extensions/ # Extension management
chrome://serviceworker-internals/ # Service worker debugging
Emergency Cleanup
If extension gets stuck or behaves oddly:
# 1. Stop service worker
# Go to chrome://serviceworker-internals/ → Stop
# 2. Clear extension storage
# DevTools → Application → Storage → Clear site data
# 3. Remove and reload extension
# chrome://extensions/ → Remove → Load unpacked again
# 4. Clean rebuild
rm -rf dist/
npm run build