Something went wrong. Try again.
Something went wrong. Try again.
# Browser Extension Setup with Plasmo
This guide walks through setting up a browser extension using Plasmo framework while reusing existing webapp components and code.
## Overview
We'll use Plasmo (Option 3) which provides:
- Built specifically for modern web extensions
- Excellent TypeScript support
- Hot reloading during development
- Handles Manifest V3 complexities
- Easy component sharing
## Setup Steps
### 1. Install Plasmo
```bash
cd src/webapp
pnpm add -D plasmo
```
### 2. File Structure
Plasmo uses convention over configuration. Extension files go directly in the webapp root:
```
src/
webapp/
app/ # Keep existing Next.js app
components/ # Keep existing components
hooks/ # Keep existing hooks
api-client/ # Keep existing API client
popup.tsx # Extension popup (root level)
options.tsx # Extension options page (root level)
content.ts # Content scripts (root level)
background.ts # Background script (root level)
package.json # Update this
```
### 3. Update package.json Scripts
```json
{
"scripts": {
"dev": "next dev",
"dev:extension": "plasmo dev",
"build": "next build",
"build:extension": "plasmo build",
"package:extension": "plasmo package"
}
}
```
### 4. File Structure
Plasmo uses convention over configuration. Extension files go directly in the webapp root:
```
src/
webapp/
app/ # Keep existing Next.js app
components/ # Keep existing components
hooks/ # Keep existing hooks
api-client/ # Keep existing API client
popup.tsx # Extension popup (root level)
options.tsx # Extension options page (root level)
content.ts # Content scripts (root level)
background.ts # Background script (root level)
package.json # Update this
```
### 5. Create Extension Entry Points
**popup.tsx:**
```typescript
import { useAuth } from "./hooks/useAuth"
import { Button, Center, Title } from…