Closed Bug 1717431 Opened 4 years ago Closed 3 months ago

clients.openWindow throws "TypeError: Unable to open window" when no window is open

Categories

(Core :: DOM: Service Workers, defect, P3)

Firefox 89
defect

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: github, Unassigned)

References

Details

(Whiteboard: dom-lws-bugdash-triage)

Attachments

(3 files)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36

Steps to reproduce:

Click any push notification when no tab nor window is open. Please note that when any window/tab is open, the problem can't be reproduced. All windows/tabs need to be closed.

Make push messaging and service worker with this function:

self.addEventListener('notificationclick', function(e) {
clients.openWindow('https://example.com').catch(function(e) {console.log(e);});
});

Actual results:

Nothing happens, no window opens. An error is reported in the service worker's logs: TypeError: Unable to open window

Expected results:

A new window/tab should have opened.

The Bugbug bot thinks this bug should belong to the 'Firefox::Messaging System' component, and is moving the bug to that component. Please revert this change in case you think the bot is wrong.

Component: Untriaged → Messaging System

I believe this is the right component for this issue, moving it over to Dom: Service Workers. Thank you for the report!

Component: Messaging System → DOM: Service Workers
Product: Firefox → Core

I believe this likely should be addressed in Firefox when running under fission thanks to the many cleanups involved, but we'll need to confirm this.

Severity: -- → S3
Priority: -- → P3

I think the bug is still present.

On my service worker implementation, the problem is simple to reproduce.

OS: MacOs Ventura
Firefox Version: Stable, 112

  1. Open firefox normal window and load web app installing service worker
  2. Open incognito window to web app responsible triggering push event on previous service worker installed
  3. close normal window
  4. from incognito window, trigger the push event

From here, the service worker receive the push event and showNotification()

  1. the user click on the notification
  2. the service worker "notificationclick" event handler triggers and fails to open the window with "self.clients.openWindow()"

Here is the linked stack overflow:

https://stackoverflow.com/questions/75997734/how-to-prevent-showing-unclickable-web-push-notifications-firefox

At current version of Firefox for Android. It opens about:blank page instead of open url.

This code navigates to url from active window. But its not a solution to open url in new window.

self.addEventListener("notificationclick", (e) => {
  e.notification.close();
  e.waitUntil(self.clients.claim().then(() => {
    // See https://developer.mozilla.org/en-US/docs/Web/API/Clients/matchAll
    return self.clients.matchAll({type: 'window'});
  }).then(clients => {
    return clients.map(client => {
      // Check to make sure WindowClient.navigate() is supported.
      if ('navigate' in client) {
        return client.navigate('https://google.com/');
      }
    });
  }));
});

Likely duplicate: https://bugzilla.mozilla.org/show_bug.cgi?id=1815380

Opening windows via clients.openWindow doesn't work at all, neither does client.focus. Both open a blank window, and clients.openWindow returns NS_ERROR_FAILURE.

Tried with Firefox Android 116.3.0 on my own device and 114.2.0 on BrowserStack.

Attached video Works in Chrome

Chrome in https://webpushtest.com/ - everything works as expected

Attached video Doesn't work in Firefox

Firefox in https://webpushtest.com/ - doesn't open the page, not even blank

Do we see the issue outside of Android? For Android we have bug 1825910 which is being worked on. If not probably we can mark this as a duplicate.

Status: UNCONFIRMED → NEW
Ever confirmed: true
See Also: → 1825910

I should check the comment #0 is still a thing, although a simple test says it's not a problem anymore, but that was a living service worker. I need to check whether a newly triggered service worker also works.

Flags: needinfo?(krosylight)

(And me realizes that we have bug 1847096, so that can't happen. So let's track the Android part in bug 1825910, the service worker startup part in bug 1847096, and close this as comment #0 doesn't happen anymore.)

Status: NEW → RESOLVED
Closed: 3 months ago
Flags: needinfo?(krosylight)
Resolution: --- → WORKSFORME
Whiteboard: dom-lws-bugdash-triage
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: