mirror of
https://github.com/bitwarden/browser
synced 2025-12-21 02:33:46 +00:00
1.0 KiB
1.0 KiB
Browser Extension - Critical Rules
-
NEVER use
chrome.*orbrowser.*APIs directly in business logic- Always use
BrowserApiabstraction:/apps/browser/src/platform/browser/browser-api.ts - Required for cross-browser compatibility (Chrome/Firefox/Safari/Opera)
- Always use
-
ALWAYS use
BrowserApi.addListener()for event listeners in popup context- Safari requires manual cleanup to prevent memory leaks
- DON'T use native
chrome.*.addListener()orbrowser.*.addListener()directly
-
CRITICAL: Safari has tab query bugs
- Use
BrowserApi.tabsQueryFirstCurrentWindowForSafari()when querying current window tabs - Safari can return tabs from multiple windows incorrectly
- Use
Manifest V3
- Extension uses Web Extension API Manifest V3
- Service workers replace background pages
- Background context runs as service worker (can be terminated anytime)
- DON'T assume background page persists indefinitely
- Use message passing for communication between contexts
chrome.extension.getBackgroundPage()returnsnullin MV3