---
title: "URL Navigation from Service Worker"
description: "Using WindowClient.navigate() to navigate controlled pages. Practical notes and code examples on URL Navigation from Service."
url: "https://h3manth.com/scribe/url-navigation-from-service-worker/"
canonical_url: "https://h3manth.com/scribe/url-navigation-from-service-worker/"
markdown_url: "https://h3manth.com/scribe/blog/url-navigation-from-service-worker.md"
publishDate: "2016-10-05T00:00:00.000Z"
author: "Hemanth HM"
category: "web"
tags: ["javascript","service-worker"]
word_count: 64
reading_time_minutes: 1
x_markdown_tokens: 259
content_signal: "ai-train=yes, search=yes, ai-input=yes"
---

# URL Navigation from Service Worker

> Using WindowClient.navigate() to navigate controlled pages. Practical notes and code examples on URL Navigation from Service.

Since service workers have readonly access to `navigator.location`, use [WindowClient.navigate](https://developer.mozilla.org/en-US/docs/Web/API/WindowClient/navigate) for navigation.

## Navigate on Activation

```javascript
self.addEventListener('activate', event => {
  event.waitUntil(
    self.clients.claim()
      .then(() => self.clients.matchAll({ type: 'window' }))
      .then(clients => {
        return clients.map(client => {
          if ('navigate' in client) {
            return client.navigate('meow.html');
          }
        });
      })
  );
});
```

The `navigate()` method returns a Promise that resolves to the existing WindowClient.

Happy navigating! 🧭
