fix(e2e): use native chrome API instead of browser polyfill in tests#3992
Conversation
WXT v0.20 removed webextension-polyfill injection (wxt-dev/wxt#1084). The browser global is no longer available in Playwright evaluate() contexts. Switch to the native chrome.* API which is always available in Chrome extension page and service worker contexts. Fixes failing extension E2E tests after renovate dependency updates.
📝 WalkthroughWalkthroughReplaces in-page WebExtension API usage from 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/extension/tests/types.d.ts (1)
6-6: Install@types/chrometo replace theanytype annotation with proper Chrome extension API signatures.The
declare const chrome: anysatisfies the compiler but loses all type checking and IDE autocomplete for everychrome.*call (e.g.,chrome.storage.local.get,chrome.history.search) in the test suite. The@types/chromepackage provides complete ambient type definitions for the Chrome Extension APIs and is fully compatible with Playwright'sevaluate()context.♻️ Proposed refactor
Install the types package:
# in apps/extension/package.json devDependencies + "@types/chrome": "^0.1.38"Then remove
apps/extension/tests/types.d.tsentirely, since@types/chromealready declareschromein the global ambient scope.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/extension/tests/types.d.ts` at line 6, Remove the manual `declare const chrome: any` in apps/extension/tests/types.d.ts and instead install the `@types/chrome` package so the global `chrome` symbol has proper Chrome extension API typings; after installing `@types/chrome` delete the custom types.d.ts file (or stop declaring `chrome`) so the ambient definitions from `@types/chrome` provide autocomplete and type-checking for all `chrome.*` calls (e.g., chrome.storage.local.get, chrome.history.search) in the tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/extension/tests/types.d.ts`:
- Line 6: Remove the manual `declare const chrome: any` in
apps/extension/tests/types.d.ts and instead install the `@types/chrome` package
so the global `chrome` symbol has proper Chrome extension API typings; after
installing `@types/chrome` delete the custom types.d.ts file (or stop declaring
`chrome`) so the ambient definitions from `@types/chrome` provide autocomplete
and type-checking for all `chrome.*` calls (e.g., chrome.storage.local.get,
chrome.history.search) in the tests.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8a324e73-352d-4557-ae0b-17c7ff85d12d
📒 Files selected for processing (6)
apps/extension/tests/auth.setup.tsapps/extension/tests/fixtures/background-fixture.tsapps/extension/tests/fixtures/base-fixture.tsapps/extension/tests/types.d.tsapps/extension/tests/utils/history-utils.tsapps/extension/tests/utils/test-utils.ts
- Add @types/chrome devDependency for proper Chrome API typing in tests - Replace 'any' type declaration with triple-slash reference to @types/chrome - Update JSDoc in test-utils.ts: browser.storage.local → chrome.storage.local - Update comment in base-fixture.ts: browser.storage.local → chrome.storage.local Addresses review comments on PR #3992.
- Remove @types/chrome dependency (WXT provides browser types, not chrome global) - Add minimal types.d.ts declaring only chrome.storage and chrome.history APIs used in tests - Keep comments and JSDoc updated to reference chrome.* instead of browser.*
- Add @types/chrome as devDependency to extension package - Remove custom types.d.ts declaration - @types/chrome provides full type safety for chrome.storage and chrome.history in test evaluate() contexts
Greptile Summary
This PR replaces the WXT
browserpolyfill with the nativechromeAPI across all Playwright e2e test utilities and fixtures, adding@types/chromefor proper type support. It also bundles several unrelated cleanups: removing unusedPropstype exports and an unusedgetCurrentUserfunction, unexporting internal-onlysaveBookmarks/savePersonshelpers inrealtimeDBService.ts, and moving@bypass/trpc's runtimedependenciestopeerDependencies.Confidence Score: 5/5
Safe to merge — no logic bugs or regressions introduced.
All changed code is either test infrastructure (browser → chrome API swap, types), dead-code removal (unused exports/functions), or lockfile/workspace hygiene. The pnpm-lock.yaml was regenerated successfully, confirming the dependency changes resolve cleanly in the monorepo.
No files require special attention.
Reviews (5): Last reviewed commit: "Remove dead code" | Re-trigger Greptile