Note
Extension and client share some code and best practices. Please read both documentations.
The HiveCache browser extension allows users to quickly capture and bookmark web pages directly from their browser.
- Language: TypeScript
- Build Tool: esbuild
- Package Manager: Yarn
- Browser APIs: Chrome Extension Manifest V3
You will need:
- Node.js (v16 or higher)
- Yarn
This project uses TypeScript, all source files are in the src/ directory:
- Edit
.tsfiles insrc/ - Run
yarn buildto compile to.jsfiles - The compiled
.jsfiles are what the browser extension uses
Install dependencies:
castor extension:installBuild the extension:
castor extension:build- Build once:
castor extension:build - Watch mode (auto-rebuild on changes):
castor extension:watch - Clean compiled files:
castor extension:clean
- Go to
chrome://extensions/ - Enable "Developer mode" (toggle in the top right)
- Click "Load unpacked"
- Select the
extension/directory
- Go to
about:debugging - Click "This Firefox" in the left sidebar
- Click "Load Temporary Add-on"
- Select
manifest.jsonfrom theextension/directory
This extension shares code with the web client through the shared/ directory at the workspace root.
The shared package contains:
- Unified API client (
shared/src/api/client.ts) - Single API client used by both extension and client - Type definitions (
shared/src/types/) - Types matching the OpenAPI specification exactly - Storage adapters (
shared/src/storage/) - Abstracted storage for browser.storage (extension) and localStorage (client) - Tag transformations (
shared/src/tag/transform.ts) - Functions to transform tags between API and internal formats - Utilities (
shared/src/utils/) - Shared utility functions
The extension uses the browserStorage adapter which wraps chrome.storage.local for token and configuration storage.
The API client is configured with this adapter in src/api.ts:
const adapter = createBrowserStorageAdapter();
const apiClient = createApiClient({
baseUrl: apiHost,
storage: adapter,
enableCache: true,
});The build process uses esbuild to bundle TypeScript files.
TypeScript path aliases (@shared/*) are configured in tsconfig.json to import from the shared package.
Esbuild resolves these imports automatically when bundling.
- Popup (
popup.html,src/popup.ts) - The main UI when clicking the extension icon - Options (
options.html,src/options.ts) - Configuration page for instance URL and authentication - Background (
background.js,src/background.ts) - Background service worker - Content Script (
content.js,src/content.ts) - Injected into web pages to extract metadata and archive pages
The extension uses Manifest V3. Key features:
activeTabpermission for accessing current tabstoragepermission for saving configurationtabspermission for communicating with content scripts- Content scripts run on all pages (
<all_urls>)