This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

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.

Syntax

ServiceWorkerClients.openWindow(url).then(function(WindowClient) {
  // do something with your WindowClient
});

Parameters

url
A USVString 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

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

Examples

// When the user clicks a notification focus the window if it exists or open
// a new one otherwise.
onotificationclick = function(event) {
  var found = false;
  clients.matchAll().then(function(clientsArr) {
    for (i = 0; i < clientsArr.length; i++) {
      if (clientsArr[i].url === event.data.url) {
        // We already have a window to use, focus it.
        found = true;
        clientsArr[i].focus();
        break;
      }
    }
    if (!found) {
      // Create a new window.
      clients.openWindow(event.data.url).then(function(windowClient) {
        // do something with the windowClient.
      });
    }
  });
};

Specifications

Specification Status Comment
Service Workers
The definition of 'Clients' in that specification.
Working Draft Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic support
Experimental
Chrome Full support 40
Full support 40
Full support 42
Notes
Notes Can only open URLs on the same origin.
Full support 43
Notes
Notes Can open any URL.
Full support 51
Notes
Notes URLs may open inside an existing browsing context provided by a standalone web app
Edge ? Firefox Full support 45
Notes
Full support 45
Notes
Notes Service workers (and Push) have been disabled in the Firefox 45 & 52 Extended Support Releases (ESR).
IE No support NoOpera Full support 38Safari No support NoWebView Android Full support 40
Full support 40
Full support 42
Notes
Notes Can only open URLs on the same origin.
Full support 43
Notes
Notes Can open any URL.
Full support 51
Notes
Notes URLs may open inside an existing browsing context provided by a standalone web app
Chrome Android Full support 40
Full support 40
Full support 42
Notes
Notes Can only open URLs on the same origin.
Full support 43
Notes
Notes Can open any URL.
Full support 51
Notes
Notes URLs may open inside an existing browsing context provided by a standalone web app
Edge Mobile ? Firefox Android Full support 45Opera Android Full support 38Safari iOS No support NoSamsung Internet Android Full support 4.0
Full support 4.0
Full support 5.0
Notes
Notes URLs may open inside an existing browsing context provided by a standalone web app

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.

Document Tags and Contributors

Last updated by: whawker,