ChatGPTBox is a cross-platform browser extension that deeply integrates ChatGPT and other AI models into web browsing. The extension provides chat dialogs, selection tools, site-specific adapters, and AI-powered features across the web.
Always reference these instructions first and fall back to search or bash commands only when you encounter unexpected information that does not match the info here.
- Install dependencies:
npm ci-- npm audit warnings may appear; for development-only dependencies they generally do not affect the shipped extension. Review and address runtime-impacting advisories separately. - Development build:
npm run dev-- runs webpack in watch mode. Do not kill mid-compilation, but stop gracefully when switching branches or after dependency/config changes, then restart to avoid stale watchers and inconsistent state. - Production build:
npm run build-- Avoid force-killing mid-bundle; stop, fix, then rebuild. See "Time Expectations" and "Build Issues" for the hung-build policy and recovery steps. - Analyze bundle:
npm run analyze-- Inspects the size of webpack output files. - Format code:
npm run pretty-- uses Prettier to format all JS/JSX/CSS files. Run this before linting. - Lint code:
npm run lint-- uses ESLint. - Safari build:
npm run build:safari(see Platform-Specific Instructions for details)
- BUILD_PARALLEL: Toggle parallel build of production variants
- Default: on (parallel). Set to
0to run sequentially (lower CPU/IO spikes on low-core machines)
- Default: on (parallel). Set to
- BUILD_THREAD / BUILD_THREAD_WORKERS: Control Babel parallelism via thread-loader
- Default: threads enabled in dev/prod; workers = CPU cores
- Set
BUILD_THREAD=0to disable; setBUILD_THREAD_WORKERS=<n>to override worker count
- BUILD_CACHE_COMPRESSION: Webpack filesystem cache compression
- Default:
0(no compression) for faster warm builds on CPU-bound SSD machines - Options:
0|false|none,gzip(orbrotliif explicitly desired) - Affects only
.cache/webpacksize/speed; does not change final artifacts - Note: Babel loader cache uses its own compression setting (currently disabled for speed) and is independent of BUILD_CACHE_COMPRESSION
- Default:
- BUILD_WATCH_ONCE (dev): When set,
npm run devruns a single build and exits (useful for timing) - BUILD_POOL_TIMEOUT: Override thread-loader production pool timeout (ms)
- Default:
2000. Increase if workers recycle too aggressively on slow machines/CI
- Default:
- BUILD_RESOLVE_SYMLINKS: When set to
1/true, re-enable Webpack symlink resolution fornpm link/pnpm workspace development. Default isfalseto improve performance and ensure consistent module identity (avoids duplicate module instances) - Source maps (dev): Dev builds emit external
.mapfiles next to JS bundles for CSP-safe debugging; production builds disable source maps
Performance defaults: esbuild handles JS/CSS minification. In development, CSS is injected via style-loader; in production, CSS is extracted via MiniCssExtractPlugin. Thread-loader is enabled by default in both dev and prod.
Production build creates multiple variants in build/ directory:
chromium/- Chromium-based browsers (Chrome, Edge) with full featuresfirefox/- Firefox with manifest v2chromium-without-katex-and-tiktoken/- Minimal build without math rendering and token encodingfirefox-without-katex-and-tiktoken/- Minimal Firefox build without math rendering and token encoding- Distribution artifacts:
- Chromium:
build/chromium.zip - Firefox:
build/firefox.zip - Safari:
Fission - ChatBox.appandsafari.dmg(see Safari Build section for details)
- Chromium:
The project uses Preact (for React-like components), SCSS (for styling), and Webpack 5 (for bundling).
- Content Script (
src/content-script/index.jsx) - Injected into all web pages, provides main chat functionality - Background Script (
src/background/index.mjs) - Handles browser APIs and cross-page communication - Popup (
src/popup/) - Extension popup interface accessible via browser toolbar - Independent Panel (
src/pages/IndependentPanel/) - Standalone chat page and side panel - Site Adapters (
src/content-script/site-adapters/) - Custom integrations for specific websites (Reddit, GitHub, YouTube, etc.) - Selection Tools (
src/content-script/selection-tools/) - Text selection features (translate, summarize, explain, etc.)
src/manifest.json- Manifest v3 for Chromium browsers (Chrome, Edge, Opera, etc.)src/manifest.v2.json- Manifest v2 for Firefox (current status; future MV3 migration may change this)- Background runs as service worker (MV3) vs background page (MV2)
- Different permission models between manifest versions
This browser extension has no automated tests, so manual testing is essential:
-
Load Extension in Browser:
- Chrome: Go to
chrome://extensions/, enable Developer Mode, click "Load unpacked", then select the folderbuild/chromium/(the folder must containmanifest.json). - Firefox: Go to
about:debugging#/runtime/this-firefox, click "Load Temporary Add-on", then select themanifest.jsonfile insidebuild/firefox/(do not select the folder directly). Note: Temporary (unsigned) add-ons are removed on browser restart; reload them via the same "This Firefox" page after every restart, and some environments with enterprise policies may block loading from file. - Important: Extension files cannot be tested by serving them via HTTP server - they must be loaded as a proper browser extension.
- Chrome: Go to
-
Core Functionality Tests:
- Press
Ctrl+B(Windows/Linux) or⌘+B(macOS) to open the chat dialog on any webpage - Select text on a page, verify selection tools appear
- Right-click and verify "Ask ChatGPT" context menu appears
- Click extension icon to open popup
- Press
Ctrl+Shift+H(Windows/Linux) or⌘+Shift+H(macOS) to open the independent conversation page
- Press
-
Site Integration Tests:
- Visit YouTube.com, verify video summary features work
- Visit Reddit.com, verify ChatGPT integration appears in sidebar
- Visit GitHub.com, verify code analysis features work
- Visit Google.com search results, verify ChatGPT responses appear
-
Configuration Tests:
- Open extension popup, navigate through tabs (General, Feature Pages, Modules > Selection Tools, Modules > Sites, Advanced)
- Test API mode switching (Web API vs OpenAI API) under Modules > API Modes
- If using Web APIs, ensure you are signed in to the provider in the same browser profile; if using API Keys, configure valid keys in settings
- Verify language settings work
Debugging tips:
- Inspect background Service Worker, page DevTools for content scripts, and use "Inspect popup" for the popup UI
- After rebuilds, reload the extension and refresh the page to re‑inject content scripts
Ensure these files exist in build/chromium/ after successful build:
manifest.json(contains proper extension metadata)background.js(service worker bundle)content-script.js(main functionality)content-script.css(styling)popup.htmlandpopup.js(popup interface)IndependentPanel.htmlandIndependentPanel.js(standalone chat page)shared.js(shared vendor/runtime; size varies by environment and dependencies)logo.png(extension icon)rules.json(declarative net request rules)
Bundle sizes are approximate and not validation criteria.
npm run verifytests search engine configurations by attempting to fetch search results from external search engines (Bing, Yahoo, Baidu, Naver) to validate that the site adapters can parse and handle real responses.- Successful validation: For each search engine, the script expects to receive a valid HTTP response (status 200) and to successfully extract and parse search results using the corresponding site adapter. If the adapter can parse the expected data structure from the response, the test is considered a pass.
- Expected failure modes: In sandboxed or CI environments, the script may fail due to network restrictions (e.g., DNS errors, timeouts, connection refused), HTTP errors (e.g., 403, 429, 503), or changes in the search engine's response format. These failures are expected and do not indicate build problems.
- If you see network or HTTP errors during
npm run verify, you can safely ignore them unless you are specifically testing or updating site adapter logic.
Usage notes:
- Default checks target:
https://www.bing.com/search?q=hello,https://search.yahoo.co.jp/search?p=hello,https://www.baidu.com/s?wd=hello,https://search.naver.com/search.naver?query=hello - Optional engines (may be blocked by region or anti-bot measures): Google, DuckDuckGo, Brave, Searx.
- Troubleshooting: If a site fails, try adjusting
Accept-Language/User-Agentheaders in the script, update the site's selector arrays with ordered fallbacks, or temporarily reduce the test to a single URL while iterating.
-
ALWAYS run
npm run lintbefore committing - CI will fail otherwise -
ALWAYS run
npm run prettyto format code consistently -
ESLint configuration in
.eslintrc.jsonenforces React/JSX standards -
Prettier configuration in
.prettierrchandles formatting -
Naming conventions: component directories use PascalCase; feature folders use kebab-case; entry files are typically
index.jsxorindex.mjs -
Avoid heavy dependencies; if necessary, justify and keep bundle size under control
Pre-commit hooks automatically:
- Run prettier formatting
- Stage formatted files
- Run lint checks
Key file locations:
- Configuration:
src/config/index.mjs - API integrations:
src/services/apis/ - Localization:
src/_locales/ - UI components:
src/components/ - Utilities:
src/utils/
- Keep changes minimal and focused. Avoid unrelated refactors in the same PR.
- Commit subject: imperative, capitalize first word; separate subject/body with a blank line; wrap at ~72 characters; explain what and why.
- PRs: link related issues, summarize scope/behavior changes; include screenshots for UI changes.
- Note i18n updates in PR description when
src/_locales/changes.
src/
├── background/ # Background script/service worker
├── components/ # Reusable UI components
├── config/ # Configuration management
├── content-script/ # Main content script and features
│ ├── site-adapters/ # Website-specific integrations
│ ├── selection-tools/ # Text selection features
│ └── menu-tools/ # Context menu features
├── pages/IndependentPanel/ # Standalone chat page
├── popup/ # Extension popup
├── services/ # API clients and wrappers
└── utils/ # Helper functions
- Run
npm run build:safari(requires macOS with Xcode installed) - Creates
Fission - ChatBox.appbundle andsafari.dmginstaller - Uses
safari/build.shscript with platform-specific patches
- Uses
webextension-polyfillfor API compatibility
- Do not commit secrets, API keys, or user data
- Keep manifest permissions minimal and justify any additions
- Centralize network/API logic under
src/services/apis/and keep endpoints auditable
- Source of truth:
src/_locales/en/main.json; do not change keys - Add new strings to
en/main.jsonfirst, then propagate to other locales - Register new locales in
src/_locales/resources.mjs - Preserve placeholders and product names; keep punctuation/quotes intact
- For Traditional Chinese (Taiwan), use
src/_locales/zh-hant/main.jsonand avoid zh‑CN terms
The extension supports multiple AI providers:
- Web (cookie-based): ChatGPT (Web), Claude (Web), Kimi.Moonshot (Web), Bing (Web), Bard (Web), Poe (Web)
- APIs (key-based): OpenAI (API), Azure OpenAI (API), Anthropic (Claude API), OpenRouter (API), AI/ML (API), DeepSeek (API), Ollama (local), ChatGLM (API), Waylaidwanderer (API), Kimi.Moonshot (API)
- Custom/self-hosted: Alternative endpoints and self-hosted backends
- Build failures: Check Node.js version (requires Node 20+), clear caches and rebuild.
- macOS/Linux:
rm -rf node_modules && npm ci && rm -rf node_modules/.cache build/ dist/ - Windows (PowerShell):
Remove-Item -Recurse -Force node_modules, build, dist; if (Test-Path node_modules\.cache) { Remove-Item -Recurse -Force node_modules\.cache }; npm ci
- macOS/Linux:
- "Module not found" errors: Usually indicate missing
npm ci
- Extension not loading: Check console for manifest errors
- API not working: Verify browser has required permissions and cookies
- Selection tools not appearing: Check if content script loaded correctly
- Adding new site adapter: Create new file in
src/content-script/site-adapters/, register it insrc/content-script/site-adapters/index.mjs, keep selectors minimal with feature detection, and verify on Chromium/Firefox - Adding new selection tool: Modify
src/content-script/selection-tools/, keep UI and logic separate, and reuse helpers insrc/utils/ - Updating API integration: Modify files in
src/services/apis/ - Adding new UI component: Create in
src/components/
- Do not interrupt builds or long-running commands unless they appear hung or unresponsive.
npm ci: ~30 secondsnpm run build: ~35 seconds (measured). Set timeout to 5-10 minutes for system variations.npm run dev: ~15 seconds initial build, then watches for changes; use Ctrl+C to stop when switching branches or after config/dependency changes.npm run lint: ~5 seconds- Manual extension testing: 5-10 minutes for thorough validation
- Safari build: 2-5 minutes (macOS only)
- ALWAYS run
npm run buildafter any code changes - ALWAYS manually load and test the built extension in a browser (no automated testing available)
- ALWAYS verify the build creates expected file structure (non-empty bundles, no missing files)
- ALWAYS test core extension functionality (popup, content script injection, keyboard shortcuts)
Always build and manually test the extension in a browser before considering any change complete. Simply running the build is NOT sufficient - you must load the extension and test actual functionality.
Most of this document was generated by AI and reviewed under human supervision. If you find any clear errors while using it, please submit corrections with supporting evidence where possible.