Register onStartup and onInstalled synchronously at the top level of a Manifest V3 service worker when those events should apply the selected proxy. For an extension intentionally fixed to one route:

function applyProxy() {
  chrome.proxy.settings.set({
    value: {
      mode: 'fixed_servers',
      rules: {
        singleProxy: {
          scheme: 'http',
          host: 'proxy.example',
          port: 8080,
        },
      },
    },
    scope: 'regular',
  }, () => {
    if (chrome.runtime.lastError) {
      console.error(chrome.runtime.lastError.message);
    }
  });
}

chrome.runtime.onStartup.addListener(applyProxy);
chrome.runtime.onInstalled.addListener(applyProxy);

The manifest must declare the proxy permission and name this background worker. For an allowed public-browsing route without proxy authentication, replace the endpoint with a candidate from the HTTP proxy list, keeping the port an integer.

onStartup is profile startup with the extension installed. onInstalled includes updates, including an unpacked-extension reload treated as an update. A window-created event describes each window and can fire repeatedly in one session.

For an extension with saved profiles or an off switch, have the handler load and apply that choice instead of resetting a hardcoded default on every update. Listener registration stays at top level; asynchronous work can begin when Chrome calls the handler.

Exercise installation and profile startup separately during development, checking the configuration result for each. They are two initialization paths, not evidence supplied by opening another window.

Artihkkalat mat laktásit