Browser-Daemon Extension Testing
Test the Chrome extension at /mnt/c/Users/Lenovo/Desktop/AI/Browser-Daemon/extension.
Extension ID: jbncedmlekgiomcopmhakilindpbmfdg.
Prerequisites
- Playwright Python installed (
python3 -m playwright install chromium) PLAYWRIGHT_BROWSERS_PATH=/tmp/pw-browsers(reinstall Chromium if /tmp was cleared between WSL sessions)- WSL2 with WSLg (provides display for headful Chrome)
Run Tests
# Core extension tests (SW boot, blocking, interception, popup, standalone mode)
cd /mnt/c/Users/Lenovo/Desktop/AI/Browser-Daemon
PLAYWRIGHT_BROWSERS_PATH=/tmp/pw-browsers python3 tests/extension_test.py
# Custom rule pipeline tests (create, inject, toggle, delete)
PLAYWRIGHT_BROWSERS_PATH=/tmp/pw-browsers python3 tests/custom_rule_test.py
Timeout: 120s for core suite, 90s for custom rule suite.
Key Quirks
- headless mode: Must use
headless=Falsein Playwright.headless=True+--headless=newsilently prevents extension loading — the browser launches but the extension never registers. No error is raised; the symptom is zero service workers and no extension ID in Preferences. --disable-extensions-except: ESSENTIAL flag — without it, Playwright launches Chrome but the extension loads lazily and the service worker may never register during the test window. Always pair with--load-extension.- full Chrome binary: Must set
executable_pathto the Chrome for Testing binary, not the headless shell (chromium-*/chrome-linux64/chrome). The headless shell doesn't support extensions at all. - Browser cache:
/tmp/pw-browsersgets wiped between WSL sessions. Reinstall withPLAYWRIGHT_BROWSERS_PATH=/tmp/pw-browsers python3 -m playwright install chromium. The patch incoreBundle.jsthat maps Ubuntu 24.x to ubuntu24.04 must also be re-applied if Playwright was reinstalled. - Extension ID discovery: When loaded via
--load-extension, Chrome does NOT create anExtensions/directory in the profile. Find the ID via: (1)context.service_workersscanning forchrome-extension://URLs, (2) regex onDefault/Preferencesfiltering out known Chrome component IDs, (3)context.pagesforchrome-extension://URLs. - chrome://extensions unavailable: Navigating to
chrome://extensionsin Playwright headless returnsnet::ERR_INVALID_URL— don't rely on it.
Test Files
tests/extension_test.py — 7 core tests
- Service worker boot (extension ID discovery, no console errors)
- Element blocking (YouTube Shorts CSS injection, TikTok FYP)
- URL interception (shorts URL redirect to origin — ERR_ABORTED = PASS)
- Content script idle after page load
- Popup rendering (brand, rules, diag rows, version)
- Standalone mode indicator (cyan dot)
- Daemon integration (HTTP /extension/status — SKIP if daemon not running)
tests/custom_rule_test.py — 6 pipeline tests
A. Rule creation via create:rule message → storage
B. Rule persistence in chrome.storage.local
C. CSS injection on target domain (verify elements hidden)
D. Rule visibility in popup UI rules list
E. Rule toggle: off removes CSS, on restores it
F. Rule deletion via delete:rule message → cleanup
Extension Code Quality Checks
When modifying the extension, verify these before running tests:
manifest.jsonpermissions: Everychrome.*API call in background.js must have a matching permission. Rungrep -n 'chrome\.' extension/background.js | grep -v 'chrome\.\(storage\|tabs\|webNavigation\|scripting\|alarms\|runtime\|action\|i18n\)'and cross-check with manifest.json. Missing permissions cause silent service worker crashes.- urlPatterns in rules: Check that no urlPattern matches the site's homepage itself (e.g.,
'*://www.tiktok.com/'on the tiktok-fyp rule), or the extension will redirect the homepage to itself, making the site unreachable. urlPatterns should target specific sub-paths like'*://*.youtube.com/shorts/*'. - Custom rule handler coverage: The extension should handle
create:rule,toggle:rule, anddelete:rulemessages. If any is missing, add both the message handler case and the implementation function.
Debugging Extension Loading
If the service worker isn't visible, launch Chrome directly with verbose logging to isolate Playwright issues:
CHROME=/tmp/pw-browsers/chromium-1223/chrome-linux64/chrome
"$CHROME" --headless=new --enable-logging=stderr --v=1 \
--load-extension=/mnt/c/Users/Lenovo/Desktop/AI/Browser-Daemon/extension \
--user-data-dir=/tmp/pw-ext-debug --no-sandbox about:blank 2>/tmp/chrome.log
Then check: grep -i "extension\|manifest\|ERR\|background.js" /tmp/chrome.log. Look for JavaScript errors in the service worker — they appear as CONSOLE errors with chrome-extension:// source URLs.
Known Limitations
- TikTok.com blocks headless browsers. Test 2 may time out on TikTok navigation — this is expected, not an extension bug. The YouTube portion passes independently.
- Test 7 always fails when daemon isn't running (expected in standalone mode).
- The AI chat (✦ button) requires an OpenRouter API key or the daemon to be running. Without either, conversational rule creation is unavailable. The programmatic
create:rulemessage works regardless.
See references/pitfalls.md for detailed debugging transcripts from this session.