[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/API/Clients/openWindow [Back]  [Original]

Clients: openWindow() - Web API | MDN

MDN Web Docs

View in English Always switch to English

Clients: openWindow()

Baseline

20184

:

openWindow() Clients URL openWindow() InvalidAccessError

Firefox

Android Chrome URL Windows Chrome

js
openWindow(url)

url

URL URL

URL WindowClient null Promise

InvalidAccessError DOMException

  • 1

js
//  OS 
if (self.Notification.permission === "granted") {
  const notificationObject = {
    body: "",
    data: { url: `${self.location.origin}/some/path` },
    // data: { url: 'http://example.com' },
  };
  self.registration.showNotification(
    "",
    notificationObject,
  );
}

// 
self.addEventListener("notificationclick", (e) => {
  // 
  e.notification.close();
  //  Window 
  e.waitUntil(
    clients.matchAll({ type: "window" }).then((clientsArr) => {
      const windowToFocus = clientsArr.find(
        (windowClient) => windowClient.url === e.notification.data.url,
      );
      if (windowToFocus) {
        //  URL 
        windowToFocus.focus();
      } else {
        //  URL 
        clients
          .openWindow(e.notification.data.url)
          .then((windowClient) => (windowClient ? windowClient.focus() : null));
      }
    }),
  );
});

Service Workers Nightly
# clients-openwindow


Web Proxy Viewer  |  New URL  |  Original Page