Clients: openWindow() method

The openWindow() method of the Clients interface creates a new top level browsing context and loads a given URL. If the calling script doesn't have permission to show popups, openWindow() will throw an InvalidAccessError.

In Firefox, the method is allowed to show popups only when called as the result of a notification click event.

In Chrome for Android, the method may instead open the URL in an existing browsing context provided by a standalone web app previously added to the user's home screen. As of recently, this also works on Chrome for Windows.





A string representing the URL of the client you want to open in the window. Generally this value must be a URL from the same origin as the calling script.

Return value

A Promise that resolves to a WindowClient object if the URL is from the same origin as the service worker or a null value otherwise.


InvalidAccessError DOMException

The promise is rejected with this exception if none of the windows in the app's origin have transient activation.

Security requirements


// Send notification to OS if applicable
if (self.Notification.permission === "granted") {
  const notificationObject = {
    body: "Click here to view your messages.",
    data: { url: `${self.location.origin}/some/path` },
    // data: { url: '' },
    "You've got messages!",

// Notification click event listener
self.addEventListener("notificationclick", (e) => {
  // Close the notification popout
  // Get all the Window clients
    clients.matchAll({ type: "window" }).then((clientsArr) => {
      // If a Window tab matching the targeted URL already exists, focus that;
      const hadWindowToFocus = clientsArr.some((windowClient) =>
        windowClient.url ===
          ? (windowClient.focus(), true)
          : false
      // Otherwise, open a new tab to the applicable URL and focus it.
      if (!hadWindowToFocus)
          .then((windowClient) => (windowClient ? windowClient.focus() : null));


Service Workers
# clients-openwindow

Browser compatibility

BCD tables only load in the browser