v1.10.82-f67ee7d
Skip to main content
← Back to Hex Proxies

Chrome Extension Proxy Setup

Configure proxies in Chrome extensions using the chrome.proxy API. Browser extension proxy setup with Hex Proxies.

Requirements

  • Chrome browser
  • Manifest V3 extension with proxy permission
  • webRequest and webRequestAuthProvider permissions

Installation

// Chrome Extension - no package install needed

Code Example

// manifest.json permissions needed:
// "permissions": ["proxy", "webRequest",
//   "webRequestAuthProvider"]

// background.js - Configure proxy
const config = {
  mode: 'fixed_servers',
  rules: {
    singleProxy: {
      scheme: 'http',
      host: 'gate.hexproxies.com',
      port: 8080,
    },
    bypassList: ['localhost', '127.0.0.1'],
  },
};

chrome.proxy.settings.set(
  { value: config, scope: 'regular' },
  () => console.log('Proxy configured')
);

// Handle proxy authentication
chrome.webRequest.onAuthRequired.addListener(
  (details, callback) => {
    callback({
      authCredentials: {
        username: 'user',
        password: 'pass',
      },
    });
  },
  { urls: ['<all_urls>'] },
  ['asyncBlocking']
);

// Toggle proxy on/off
function toggleProxy(enabled) {
  if (enabled) {
    chrome.proxy.settings.set(
      { value: config, scope: 'regular' }
    );
  } else {
    chrome.proxy.settings.clear({ scope: 'regular' });
  }
}

Setup Steps

1

Set up manifest.json

Declare proxy, webRequest, and webRequestAuthProvider permissions in your Manifest V3 extension.

2

Configure proxy in background.js

Call chrome.proxy.settings.set() with fixed_servers mode pointing to gate.hexproxies.com:8080.

3

Add auth listener

Register webRequest.onAuthRequired with asyncBlocking to inject Hex Proxies credentials transparently.

4

Build toggle UI

Create a popup with an on/off switch that calls chrome.proxy.settings.set() or .clear().

5

Add bypass list

Exclude localhost, 127.0.0.1, and internal domains from proxy routing.

6

Test in Chrome

Load the extension unpacked, enable the proxy, and verify httpbin.org/ip shows a Hex Proxies IP.

Configuration Options

OptionDescription
Proxy Modefixed_servers for consistent proxy routing, pac_script for domain-based rules, direct to bypass.
Bypass ListExclude localhost, 127.0.0.1, and internal addresses from proxy routing.
Auth HandlerwebRequest.onAuthRequired with asyncBlocking for transparent credential injection.
Scoperegular for all windows, incognito_persistent for incognito-only proxy.
Togglechrome.proxy.settings.set() to enable, .clear() to disable proxy.

Best Practices

  • Use Manifest V3 with service workers for future compatibility; Manifest V2 is deprecated.
  • Store proxy credentials in chrome.storage.local, never hardcode in background.js source.
  • Add a bypass list for localhost and internal addresses to avoid routing local traffic through the proxy.
  • Implement chrome.proxy.onProxyError listener to detect and log proxy connectivity issues.
  • Use chrome.proxy.settings.get() on extension startup to verify your settings are not overridden.
  • Build a popup UI with connection status indicator and on/off toggle for user-friendly operation.
  • Use PAC script mode for advanced routing rules like proxying only specific domains.
  • Handle chrome.runtime.onInstalled to re-apply proxy settings after extension or Chrome updates.

Chrome Extension Proxy Setup

Chrome's Extension API provides the chrome.proxy namespace for routing browser traffic through proxy servers. This API is exclusive to browser extensions and offers capabilities not available through any other method: system-wide proxy routing, per-profile proxy isolation, PAC script support for complex routing rules, and programmatic proxy toggle.

Building a proxy extension with Hex Proxies lets end users switch between proxy-enabled and direct browsing with a single click. The extension handles authentication transparently through the webRequest.onAuthRequired listener, so users never see a proxy login prompt.

Prerequisites

Before you begin, make sure you have: - An active Hex Proxies account with proxy credentials - Chrome browser - Manifest V3 extension with proxy permission - webRequest and webRequestAuthProvider permissions

Manifest Configuration

Your manifest.json must declare the proxy, webRequest, and webRequestAuthProvider permissions. Without webRequestAuthProvider, Chrome cannot use asyncBlocking mode for the authentication listener.

Basic Proxy Configuration

Use chrome.proxy.settings.set() with a fixed_servers mode configuration pointing to gate.hexproxies.com:8080.

// manifest.json permissions needed:
// "permissions": ["proxy", "webRequest",

// background.js - Configure proxy const config = { mode: 'fixed_servers', rules: { singleProxy: { scheme: 'http', host: 'gate.hexproxies.com', port: 8080, }, bypassList: ['localhost', '127.0.0.1'], }, };

chrome.proxy.settings.set( { value: config, scope: 'regular' }, () => console.log('Proxy configured') );

// Handle proxy authentication chrome.webRequest.onAuthRequired.addListener( (details, callback) => { callback({ authCredentials: { username: 'user', password: 'pass', }, }); }, { urls: ['<all_urls>'] }, ['asyncBlocking'] );

// Toggle proxy on/off function toggleProxy(enabled) { if (enabled) { chrome.proxy.settings.set( { value: config, scope: 'regular' } ); } else { chrome.proxy.settings.clear({ scope: 'regular' }); } } ```

PAC Script Mode for Advanced Routing

For complex routing rules like proxying only specific domains or using different proxies per destination, use mode: 'pac_script' with an inline PAC function. This lets you route social media through one Hex Proxies region and ecommerce through another.

Incognito Scope Isolation

Set scope: 'incognito_persistent' to apply proxy settings only in incognito windows, keeping regular browsing direct. This is useful for testing proxy behavior without affecting your normal browsing session.

Extension Conflict Resolution

Only one extension can control chrome.proxy.settings at a time. Chrome uses a priority system where the most recently installed extension wins. Use chrome.proxy.settings.get() to verify your settings are active and not overridden by another extension.

Configuration Options

  • **Proxy Mode** -- fixed_servers for single proxy, pac_script for domain-based routing, direct for no proxy.
  • **Bypass List** -- Array of domains and IP ranges excluded from proxy routing (localhost, internal networks).
  • **Auth Handler** -- webRequest.onAuthRequired with asyncBlocking mode for transparent credential injection.
  • **Scope** -- regular for all windows, incognito_persistent for incognito only.
  • **Toggle** -- chrome.proxy.settings.clear() to disable, .set() to re-enable.

Error Handling

Chrome extension proxy errors require checking both the chrome.runtime.lastError and proxy-specific error events.

  1. chrome.proxy.settings.set() silently fails
  2. - Another extension is overriding your proxy settings
  3. - Check chrome://extensions for conflicting proxy extensions
  4. - Use chrome.proxy.settings.get() to verify your config is active

2. onAuthRequired not firing - Missing webRequestAuthProvider permission in manifest.json - Ensure asyncBlocking is in the extraInfoSpec array - Verify the listener URL filter matches the proxy auth challenge

3. ERR_PROXY_CONNECTION_FAILED in browser - The proxy server is unreachable from the user's network - Add a connectivity check in the extension popup - Fall back to direct mode with chrome.proxy.settings.clear()

4. Bypass list not working - Entries must be hostnames without protocol prefix - Use <local> keyword for all local addresses - Wildcards: *.example.com for all subdomains

5. Extension disabled after Chrome update - Manifest V2 extensions may be auto-disabled - Migrate to Manifest V3 with service workers - Use chrome.runtime.onInstalled to re-apply proxy settings after updates ```

Use chrome.proxy.onProxyError listener to catch and log proxy errors that occur during browsing.

Error Handling

## Error Handling

Chrome extension proxy errors require checking both the chrome.runtime.lastError and proxy-specific error events.

1. chrome.proxy.settings.set() silently fails - Another extension is overriding your proxy settings - Check chrome://extensions for conflicting proxy extensions - Use chrome.proxy.settings.get() to verify your config is active

2. onAuthRequired not firing - Missing webRequestAuthProvider permission in manifest.json - Ensure asyncBlocking is in the extraInfoSpec array - Verify the listener URL filter matches the proxy auth challenge

3. ERR_PROXY_CONNECTION_FAILED in browser - The proxy server is unreachable from the user's network - Add a connectivity check in the extension popup - Fall back to direct mode with chrome.proxy.settings.clear()

4. Bypass list not working - Entries must be hostnames without protocol prefix - Use <local> keyword for all local addresses - Wildcards: *.example.com for all subdomains

5. Extension disabled after Chrome update - Manifest V2 extensions may be auto-disabled - Migrate to Manifest V3 with service workers - Use chrome.runtime.onInstalled to re-apply proxy settings after updates ```

Use chrome.proxy.onProxyError listener to catch and log proxy errors that occur during browsing.

Frequently Asked Questions

Can Chrome extensions handle proxy authentication?

Yes. Use webRequest.onAuthRequired with asyncBlocking mode to inject username and password for every proxy auth challenge transparently.

What happens if another extension also sets a proxy?

Chrome uses priority ordering. The most recently installed extension controls proxy settings. Use chrome.proxy.settings.get() to verify your config is active.

How do I route only specific sites through the proxy?

Use mode: pac_script with an inline FindProxyForURL function that returns PROXY for target domains and DIRECT for everything else.

Does this work in Manifest V3?

Yes. The chrome.proxy API works in Manifest V3. Use a service worker instead of a background page for the auth listener.

Ready to Get Started?

Set up Chrome Extension with Hex Proxies in minutes.