A Page Keeps Opening an Old URL? Check the Service Worker

Find out whether a service worker redirects to an old URL using browser developer tools, a clean profile, and an isolated local navigation test.

Published
Reading time
7 min read
A Page Keeps Opening an Old URL? Check the Service Worker
On this page

If a page keeps opening an old URL even though the server appears to return the right response, a service worker may be intercepting the navigation. This guide shows how to distinguish a server redirect from a service-worker response and reproduce the difference in an isolated local test.

Key Takeaways

  • A controlled browser can receive a navigation response from a service worker instead of directly from the server.
  • Compare the browser’s document request with a server-side GET, then repeat with the worker bypassed and in a clean browser profile.
  • A service worker can return a redirect or cached HTML containing its own redirect logic. Neither necessarily appears in a command-line status check.
  • Unregister workers only in an authorized test environment, and account for pages that register them again.

First, locate the redirect

Open your browser’s developer tools before navigating to the affected page. In the Network panel, enable Preserve log, clear the existing entries, and load the exact URL that leads to the old destination.

Select the initial document request and inspect its status, response headers, and any subsequent document requests. A 3xx response with a Location header is a redirect response, but its presence alone does not prove that the server produced it: a service worker can supply a redirect response too.

Look for a service-worker indicator in the request’s source, size, or other details. The wording and location vary by browser. Also inspect the final page and any scripts: JavaScript, a meta refresh, or a client-side router can change the URL without an HTTP redirect on the initial request.

Now request the same URL outside the browser, without automatically following redirects:

curl -sS -D - -o /dev/null 'https://example.com/path'

Replace the example URL with an authorized test URL. This sends a GET and prints the response headers, including any status and Location header. It does not execute page JavaScript or use the browser’s service worker. It may still reach a CDN, proxy, or other intermediary rather than your origin server.

Compare equivalent requests where possible: scheme, hostname, path, query string, authentication, cookies, and relevant headers can all affect the response. Do not paste sensitive cookies or credentials into shared logs. A different result is a useful clue, not proof of a worker: browser extensions, client-side code, caches, and request differences can also explain it.

Advertisement

Check whether a service worker controls the page

In the affected browser tab’s console, run:

navigator.serviceWorker.controller

A non-null result identifies the worker controlling the current document. A null result means that document is not currently controlled; it does not rule out a registration that could control a later navigation. Check the relevant registration as well:

await navigator.serviceWorker.getRegistration(location.href)

Run these checks on the relevant origin and page, including after the unexpected navigation if necessary. A worker’s scope matters: a registration may apply to one path but not another, and a worker controlling the final page is not by itself proof that it caused the earlier redirect.

In developer tools, inspect the site’s service-worker registration, script URL, scope, and lifecycle state. In Chromium-based browsers, these details are typically under Application → Service Workers. Labels and locations differ across browsers. Look for an older worker still active while a newer worker is waiting, or for a script and scope that are not what you expect.

Compare with the worker bypassed

If your browser offers a Bypass for network option for service workers, enable it in developer tools and repeat the navigation with the Network log preserved. Record whether the initial document response and destination change. Disable the option afterward.

Bypassing the worker is a diagnostic comparison, not a permanent fix. Likewise, disabling the browser’s HTTP cache is not the same as bypassing service-worker fetch handling: a worker may still return its own response or read from Cache Storage.

Repeat the navigation in a clean browser profile with no existing site data or extensions. Keep the request conditions as similar as practical; a new profile may lack cookies or authentication. If the clean profile behaves differently, investigate its differences before attributing the cause solely to the worker.

Reproduce the difference with a local test page

This isolated example makes the server serve target.html, while a controlling worker redirects navigation to old.html. It is for local diagnosis, not a production configuration. Use a fresh test directory and an unused local port; do not place the worker in an existing site’s directory or origin.

These examples were not executed in this environment. The MDN Service Worker API documentation and the Service Workers specification could not be consulted here, so verify browser-specific behavior against them when diagnosing your application.

Create the following four files in the same empty directory. First, index.html:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Service worker navigation test</title>
</head>
<body>
  <h1>Navigation test</h1>
  <p><a href="./target.html">Open the target page</a></p>
  <p id="status">Registering worker…</p>
  <script>
    const status = document.querySelector('#status');

    if (!('serviceWorker' in navigator)) {
      status.textContent = 'Service workers are unavailable in this context.';
    } else {
      navigator.serviceWorker.register('./sw.js')
        .then(() => navigator.serviceWorker.ready)
        .then(() => {
          status.textContent = navigator.serviceWorker.controller
            ? 'This page is controlled. Open the target page.'
            : 'Worker is ready. Reload this page, then open the target page.';
        })
        .catch((error) => {
          status.textContent = `Registration failed: ${error.message}`;
        });
    }
  </script>
</body>
</html>

Create sw.js:

self.addEventListener('fetch', (event) => {
  const target = new URL('target.html', self.registration.scope);
  const oldPage = new URL('old.html', self.registration.scope);
  const requestURL = new URL(event.request.url);

  if (event.request.mode === 'navigate' &&
      requestURL.origin === target.origin &&
      requestURL.pathname === target.pathname) {
    event.respondWith(Promise.resolve(Response.redirect(oldPage.href, 302)));
  }
});

Create target.html:

<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>Target</title></head>
<body><h1>Server target page</h1></body>
</html>

Create old.html:

<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>Old page</title></head>
<body><h1>Old page</h1></body>
</html>

From that directory, start a local server with Python installed:

python3 -m http.server 8765 --bind 127.0.0.1

Open http://127.0.0.1:8765/ in a browser. Service workers require a secure context; loopback addresses are generally treated as trustworthy for local development. Wait for the registration message, reload if instructed, and confirm that navigator.serviceWorker.controller is non-null. Then open the target link with the Network panel recording.

The code is intended to redirect that navigation to old.html. Compare it with a direct GET that does not use the worker:

curl -sS -D - -o /dev/null 'http://127.0.0.1:8765/target.html'

The local server should serve the target file without the worker’s redirect. In the browser, use the service-worker bypass option and navigate to the target again. If your observations differ, inspect registration errors, scope, the worker’s state, and the document requests before drawing conclusions.

Advertisement

Remove the test worker and investigate the real cause

In the isolated test environment, close other tabs using the test origin. From the test page’s console, unregister its matching registration:

const registration = await navigator.serviceWorker.getRegistration(location.href);
if (registration) {
  await registration.unregister();
}

Then close the test tab and open http://127.0.0.1:8765/target.html directly in a new tab. The example’s index.html registers the worker again if opened, so avoid revisiting it until you are ready to repeat the experiment. Stop the local server when finished.

Unregistering does not necessarily remove a worker from an already controlled open document immediately. Other tabs or application code can also register it again. Avoid bulk-unregistering workers or clearing site data on a production origin without authorization and a plan for the effects on users.

For the real application, inspect the worker’s navigation handler and any cached responses it uses. An old destination may be hard-coded in the worker, returned by a cached document, or generated by application code in that document. Check deployment and update behavior as well: replacing a worker script does not guarantee every open client immediately uses the replacement. Fix the source of the stale response, then verify both existing and fresh clients under your application’s update strategy.

Common Mistakes

  • Checking only curl or a server status tool. Those requests do not reproduce a browser’s service-worker interception or page scripts.
  • Treating every 3xx as an origin-server redirect. Establish whether the browser received the response from a worker, server, or intermediary.
  • Inspecting only the final URL. Preserve the network log and examine the initial document request and the navigation chain.
  • Assuming an active registration controls every path or tab. Check scope, lifecycle state, and the current document’s controller.
  • Clearing production site data as a first step. Use a clean profile or isolated test origin first, and preserve evidence for debugging.

Best Practices

Keep a record of the URL, request conditions, worker script URL and scope, and observed navigation chain. Compare normal and bypassed behavior before changing registrations. When deploying a fix, check how open tabs receive worker updates and how obsolete cached documents are retired; choose an update strategy appropriate to the application rather than assuming an immediate switch.

Conclusion

A server-side GET is a useful baseline, but it cannot show what a service worker returns to a controlled browser. Inspect the document request, compare a worker-bypassed navigation, and reproduce the behavior in an isolated environment before changing the application or its registrations.

What would your domain sell for?

A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.