notifications icon indicating copy to clipboard operation
notifications copied to clipboard

No notifications from open chat when Chrome is in background

Open RTechSn opened this issue 1 year ago • 17 comments

How to use GitHub

  • Please use the 👍 reaction to show that you are affected by the same issue.
  • Please don't comment if you have no relevant information to add. It's just extra noise for everyone subscribed to this issue.
  • Subscribe to receive notifications on status change and new comments.

Steps to reproduce

  1. Have a chat with another account open.
  2. Have no notifications from other apps
  3. Minimize or obstruct your browser window
  4. Send a message from another account

Expected behaviour

Notifications should appear

Actual behaviour

Notifications appear after unminimizing the window, or not appear at all

Talk app

Talk app version: 19.0.0

Custom Signaling server configured: yes/no and version (see Talk administration settings: /index.php/index.php/settings/admin/talk#signaling_server)

Custom TURN server configured: Yes

Custom STUN server configured: Yes

Browser

Microphone available: yes

Camera available: no

Operating system: Windows

Browser name: Chrome

Browser version: 123

RTechSn avatar May 17 '24 14:05 RTechSn

Actually we improved exactly these scenarios in the Talk 18 version. At least when switching to another tab that is. When overlapping the browser with another window that is not detectable from within the website as far as I recall, but @Antreesy might know more

nickvergessen avatar Jun 07 '24 14:06 nickvergessen

i also really need notifications to work when the browser tab is not active

ratmix avatar Jun 08 '24 02:06 ratmix

Likewise. For me on Desktop the notification is suspended until the Spreed tab is focused - defeating the purpose of the notification.

9joshua avatar Jun 08 '24 03:06 9joshua

2024-06-10 103325

As you can see, message is received by the client, but the notification is somehow suppressed, until you unminimize the window.

RTechSn avatar Jun 10 '24 07:06 RTechSn

See https://github.com/nextcloud/spreed/pull/10544 : Conversation session is considered active (and you won't receive notiication for this exact conversation only) when:

  • Tab is active - always;
  • Tab is blurred, but in foreground (visible or obstructed by another window) - first 3 minutes :warning:;

Then you should see a request like nextcloud.local/ocs/v2.php/apps/spreed/api/v4/room/{token}/participants/state to server with payload 0: image

Same request is sent when you:

  • Minimize the window to background
  • Switch to another tab in the same window

Though in that case, you shouldn't receive any notifications from server (304 response status). Apart from it, we are not blocking any native pop-ups by code.

Antreesy avatar Jun 10 '24 09:06 Antreesy

2024-06-11 100806 @Antreesy I've checked again, here you can see that the session is marked as inactive and the notification has been received by the browser. But there is no pop-up notification, until you focus the window. This bug occurs only if you have no other notifications and only on Chromium browsers.

RTechSn avatar Jun 11 '24 07:06 RTechSn

I've checked again, here you can see that the session is marked as inactive and the notification has been received by the browser. But there is no pop-up notification, until you focus the window. This bug occurs only if you have no other notifications and only on Chromium browsers.

Thanks for the confirmation, will try to reproduce it

Antreesy avatar Jun 11 '24 07:06 Antreesy

Yep, reproducible for me. As I understood it, issue seems to be on Notifications app side (frontend):

  • If tab is inactive, browser suspend some processes. In this particular case, a rendering of new components (<Notifcation />) which are creating a natie browser notification.
  • Unless tab is selected as active again (or at least hovered to show a tab preview, which sometimes also triggers a re-render), component won't be mounted.
  • Solution would be to move the native notification creation to the <NotificationsApp />, but that require a rework. Small patch for testing is under details:
// in NotificationsApp
	watch:{
		notifications(value) {
			console.log('watch notifications', value)
			if (value[0]?.shouldNotify
				&& this.showBrowserNotifications
				&& this.webNotificationsThresholdId < value[0]?.notificationId) {
				const n = new window.Notification(value[0]?.subject, {
					title: value[0]?.subject,
					lang: OC.getLocale(),
					body: value[0]?.message,
					icon: value[0]?.icon,
					tag: value[0]?.notificationId,
				})
			}
		},
	},

Transferring this issue to nextcloud/notifications repo

Antreesy avatar Jun 11 '24 11:06 Antreesy

We are checking only active/inactive state. We can also check for frozen/ discarded states for suspended tabs.

I'd say that a proper solution is to move notifications completely out from any DOM rendering, best to a worker to not be a part of the page that can be frozen.

ShGKme avatar Jun 11 '24 13:06 ShGKme

While yes, let's first do the quick fix of moving it to the root component

nickvergessen avatar Jun 13 '24 08:06 nickvergessen

For the reference:

  • Page Lifecycle API: https://developer.chrome.com/docs/web-platform/page-lifecycle-api
  • Lifecycle diagram: https://developer.chrome.com/docs/web-platform/page-lifecycle-api/image/page-lifecycle-api-state.svg
  • See and change page state: chrome://discards

In a frozen state, DOM is not updated, but background tasks are still running.

In a discarded state, no new task from the task queue will be executed.

So, to support discarded state or true push notifications, we would need to use workers what most of our libraries do not support.

ShGKme avatar Jun 13 '24 10:06 ShGKme

This particular issue seems to be fixed in the last update (29.0.3). Should this issue be closed, or should it remain open, until the proper solution with the support of discarded state be implemented?

RTechSn avatar Jun 26 '24 07:06 RTechSn

should it remain open, until the proper solution with the support of discarded state be implemented?

Yes, we wanted to keep track it and look into web workers usage in the future for handling notifications. You may unsubscribe from receiving a notifications from this issue to not suddenly be bothered one day. Thanks again for the help with investigation!

Antreesy avatar Jun 26 '24 07:06 Antreesy

Hi

I have issues generally in Nextcloud notifications. In both Desktop PWA and in browser. The notifications do not arrive and are not shown when the Windows is minimized (PWA and NC webpage). As soon as I open the Window, the notifications are shown (not always quickly, but at least they arrive).

The notifications are in general too slow.

Is it related to this issue and planned for 29.0.4, or is it not related?

I am using 29.0.0

MohammedNoureldin avatar Jun 27 '24 21:06 MohammedNoureldin

I am using 29.0.0

Then update please. Mostlikely it's fixed in 29.0.2 via https://github.com/nextcloud/notifications/pull/1948

nickvergessen avatar Jun 27 '24 22:06 nickvergessen

Thanks a lot @nickvergessen! I confirm that it works now with 29.0.3.

Nevertheless, the notification on the desktop (Web or PWA) is slow, it takes always about 20-30 seconds for the notification to arrive and get shown in Windows. Is there anything we can do for it?

MohammedNoureldin avatar Jun 27 '24 23:06 MohammedNoureldin

Is there anything we can do for it?

Yeah we do 30 second polling. So can be between 0 and 29 seconds. You can install this additional tool that will create a websocket connection with the clients and browser so that notifications can be pushed live: https://github.com/nextcloud/notify_push

nickvergessen avatar Jun 28 '24 06:06 nickvergessen