@gramercytech/gx-toolkit
Version:
Dev tools for create platform plugins
134 lines (97 loc) ⢠4.75 kB
Markdown
# Traffic Proxy Firefox Extension
A Firefox extension that intercepts and redirects web traffic to alternative domains based on configurable regex patterns.
## Features
- š **Traffic Interception**: Intercepts fetch calls and XMLHttpRequests
- šÆ **Regex Pattern Matching**: Flexible domain matching using regular expressions
- š“š¢ **Visual Toggle**: Red/green toolbar button indicating proxy status
- āļø **Settings Panel**: Easy-to-use interface for managing proxy rules
- š **Notifications**: Real-time notifications when traffic is being proxied
- š¾ **Persistent Storage**: Rules and settings are saved between browser sessions
## Installation
### Method 1: Temporary Installation (Development)
1. Open Firefox and navigate to `about:debugging`
2. Click "This Firefox" on the left sidebar
3. Click "Load Temporary Add-on"
4. Navigate to the extension folder and select `manifest.json`
### Method 2: Creating an XPI Package
1. Zip all extension files:
```bash
zip -r traffic-proxy-extension.xpi manifest.json background.js content.js popup.html popup.js icons/
```
2. Install the XPI file through Firefox's Add-ons manager
## Icon Setup
The extension includes SVG icon files that need to be converted to PNG format:
1. Open `icons/create_icons.html` in your browser
2. Click the download buttons to get PNG files
3. Save them in the `icons/` directory with the correct names
Alternatively, use an online SVG to PNG converter for the files in `icons/`.
## Usage
### Enabling the Proxy
1. Look for the Traffic Proxy button in your Firefox toolbar
2. Click the button to open the settings panel
3. Click the toggle button to enable/disable the proxy
- š“ Red = OFF
- š¢ Green = ON
### Adding Proxy Rules
1. Open the extension settings panel
2. Click "+ Add Rule"
3. Enter a regex pattern for the domain to intercept (e.g., `api\.example\.com`)
4. Enter the redirect domain (e.g., `api.alternative.com`)
5. Click "Save Changes"
### Example Rules
| Pattern | Redirect To | Description |
|---------|-------------|-------------|
| `api\.example\.com` | `api.alternative.com` | Redirect all API calls from example.com to alternative.com |
| `.*\.googleapis\.com` | `api.myproxy.com` | Redirect all Google API calls to your proxy server |
| `cdn\.jsdelivr\.net` | `my-cdn.example.com` | Redirect CDN requests to your own server |
## How It Works
1. **Background Script**: Handles webRequest interception and manages extension state
2. **Content Script**: Intercepts JavaScript fetch() and XMLHttpRequest calls
3. **Popup Interface**: Provides user interface for configuration
4. **Storage**: Saves rules and settings using Firefox's local storage API
## Permissions
The extension requires the following permissions:
- `webRequest` & `webRequestBlocking`: To intercept and modify network requests
- `<all_urls>`: To intercept requests from any website
- `storage`: To save proxy rules and settings
- `notifications`: To show proxy activity notifications
- `activeTab`: To access the current tab information
## Development
### File Structure
```
āāā manifest.json # Extension manifest
āāā background.js # Background script (main logic)
āāā content.js # Content script (fetch/XHR interception)
āāā popup.html # Settings panel HTML
āāā popup.js # Settings panel JavaScript
āāā icons/ # Extension icons
ā āāā icon-off-*.png # Red icons (proxy disabled)
ā āāā icon-on-*.png # Green icons (proxy enabled)
āāā README.md # This file
```
### Testing
1. Enable the extension
2. Add a test rule (e.g., `httpbin\.org` ā `postman-echo.com`)
3. Visit a website that makes requests to the target domain
4. Check the browser's Network tab to verify redirections
5. Verify notifications appear when traffic is proxied
## Security Considerations
- This extension can intercept ALL network traffic when enabled
- Only install from trusted sources
- Review proxy rules carefully before enabling
- Be aware that redirected traffic may be logged by the target servers
## Troubleshooting
### Extension Not Working
- Check that the extension is enabled in `about:addons`
- Verify permissions are granted
- Check browser console for errors
### Icons Not Showing
- Ensure PNG icon files exist in the `icons/` directory
- Convert SVG files to PNG if needed
- Check file permissions
### Rules Not Matching
- Test regex patterns using online regex testers
- Ensure domains are properly escaped (use `\.` for literal dots)
- Check that the proxy is enabled (green button)
## License
This extension is provided as-is for educational and development purposes.