Skip to content

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Netreq - Browser Extension for Request Redirection

A powerful Chrome/Brave/Edge browser extension that intercepts and redirects API requests from a source URL to a target URL while preserving all headers, parameters, and request bodies.

Features

✨ Request Interception & Redirection

  • Intercept requests matching a source URL prefix
  • Redirect them to a target URL transparently
  • All headers, query parameters, and request bodies are preserved

πŸ” Header Preservation

  • All original request headers are automatically copied to redirected requests
  • Authorization headers, cookies, and custom headers are maintained
  • CORS headers are handled correctly

πŸ“ Query Parameters & Path Preservation

  • URL parameters and query strings are automatically included
  • Request paths are properly appended to the target URL
  • Full payload bodies are forwarded

πŸŽ›οΈ Easy Configuration

  • Simple popup interface for quick setup
  • Advanced options page for detailed configuration
  • Enable/disable toggle for quick activation

πŸ“Š Debug Logging

  • Real-time logging of intercepted requests
  • Request details and redirect information
  • Status tracking and configuration display

Installation

For Chrome/Brave/Edge:

  1. Clone or download this repository
  2. Open your browser and navigate to chrome://extensions/ (Chrome) or brave://extensions/ (Brave)
  3. Enable "Developer mode" (toggle in top-right corner)
  4. Click "Load unpacked" and select the extension folder
  5. The extension will appear in your extensions list

For Firefox:

The extension uses Manifest V3 which is Chrome-based. Firefox support would require a Manifest V2 conversion.

Usage

Quick Setup

  1. Click the Netreq icon in your browser toolbar
  2. Enter Source URL Prefix: The URL prefix to intercept (e.g., https://backendhach.com)
  3. Enter Target/Redirect URL: Where requests should go (e.g., https://staging-api.example.com)
  4. Click "Save Configuration"
  5. Enable the toggle to activate request redirection

Example

Configuration:

  • Source Prefix: https://api.myapp.com
  • Target URL: https://api.staging.com

Result:

  • Request to: https://api.myapp.com/users/123?role=admin
  • Gets redirected to: https://api.staging.com/users/123?role=admin
  • All headers (Authorization, Content-Type, etc.) are preserved
  • Request body (if POST/PUT/PATCH) is forwarded as-is

How It Works

Request Interception Flow

1. Browser initiates request
   ↓
2. Extension's background service worker intercepts it
   ↓
3. Checks if URL matches source prefix
   ↓
4. If match found:
   - Extracts endpoint/path from original URL
   - Constructs new URL with target URL + endpoint
   - Preserves all headers
   - Preserves request body
   ↓
5. Redirects request to target URL
   ↓
6. Browser sends request with all original details

File Structure

netreq-extension/
β”œβ”€β”€ manifest.json        # Extension configuration and permissions
β”œβ”€β”€ background.js        # Main request interception logic
β”œβ”€β”€ popup.html          # Quick settings popup
β”œβ”€β”€ popup.js            # Popup functionality
β”œβ”€β”€ options.html        # Advanced settings page
β”œβ”€β”€ options.js          # Options page functionality
β”œβ”€β”€ styles.css          # Styling for popup and options
└── images/             # Extension icons (16x16, 48x48, 128x128)

Technical Details

Permissions Used

  • webRequest - Intercept HTTP requests
  • webRequestBlocking - Block and modify requests
  • storage - Store configuration locally
  • tabs - Access tab information
  • webNavigation - Monitor page navigation

Key Components

Background Service Worker (background.js)

  • Intercepts requests using chrome.webRequest.onBeforeRequest
  • Modifies headers using chrome.webRequest.onBeforeSendHeaders
  • Handles response headers with chrome.webRequest.onHeadersReceived
  • Logs request completion and errors
  • Manages configuration storage

Popup Interface (popup.html + popup.js)

  • Quick toggle to enable/disable redirection
  • Configure source and target URLs
  • Display current status
  • Auto-save functionality

Options Page (options.html + options.js)

  • Detailed configuration interface
  • Advanced settings
  • Debug logging interface
  • Import/export configuration
  • Clear log functionality

Configuration Details

Storage Format

Configurations are stored in Chrome's local storage as JSON:

{
  "enabled": true,
  "sourcePrefix": "https://api.myapp.com",
  "targetUrl": "https://api.staging.com"
}

URL Matching

  • Uses prefix matching (not full URL matching)
  • Source prefix should include protocol (http/https)
  • Trailing slashes matter: https://api.com β‰  https://api.com/

Advanced Features

Request Logging

The extension logs all intercepted requests to the browser console and the debug panel:

  • Request URL
  • Redirect target
  • Response status code
  • Any errors encountered

Header Handling

All headers are automatically preserved:

  • Authorization headers (Bearer tokens, API keys, etc.)
  • Content-Type headers
  • Custom headers
  • CORS headers
  • Cookies

Request Body Preservation

  • POST, PUT, PATCH request bodies are fully preserved
  • JSON payloads are maintained
  • Form data is preserved
  • File uploads are handled correctly

Troubleshooting

Requests Not Being Redirected

  1. Check if extension is enabled: Look at popup status
  2. Verify source prefix: Make sure it exactly matches the request URL
  3. Check configuration: Open options page to see saved settings
  4. Look at debug log: Check the options page debug console for errors

Headers Not Copied

The extension copies headers automatically. If specific headers are missing:

  1. Check browser console for errors
  2. Verify the target server accepts the headers
  3. Some security headers might be filtered by the browser

CORS Issues

If you see CORS errors:

  1. The extension doesn't bypass CORS - it only redirects requests
  2. The target server must accept requests from your origin
  3. Configure appropriate CORS headers on the target server

Security Considerations

  • The extension only operates on locally-stored configuration
  • No data is sent to external servers
  • All redirection happens locally in the browser
  • Configuration is stored only in Chrome's local storage

Limitations

  • Manifest V3 only (Chrome/Brave/Edge)
  • Cannot redirect WebSocket connections (only HTTP/HTTPS)
  • Cross-origin redirects may fail due to browser security restrictions
  • Cannot modify some security-related headers

Development

Making Changes

  1. Edit the relevant file (background.js, popup.js, etc.)
  2. Reload the extension in chrome://extensions/
  3. Test in your browser

Testing

  1. Open the extension popup to check basic functionality
  2. Open the options page to view debug logs
  3. Open DevTools (F12) β†’ Background page to see background script logs
  4. Monitor Network tab to verify redirects

License

This extension is provided as-is for personal and educational use.

Support & Issues

For issues or feature requests, please check:

  1. Debug log in options page
  2. Browser console for errors
  3. Ensure configuration is correct
  4. Verify target URL is accessible

Version: 1.0.0
Compatibility: Chrome 88+, Brave, Edge, other Chromium-based browsers

About

Netreq - URL Request Redirector Browser Extension. Redirect API requests from a source URL prefix to a target URL while preserving all headers, parameters, and payloads. Perfect for development, testing, and debugging.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages