Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications do not work correctly #5051

Open
brendrch opened this issue Jan 23, 2025 · 0 comments
Open

Notifications do not work correctly #5051

brendrch opened this issue Jan 23, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@brendrch
Copy link

What happened?

I use Webview2 version 1.0.2957.106 with C# and load a web site over https which use push notifications.
It works correctly with Chrome, Firefox and Edge browsers but not with WebView2.

On the Javascript side the notifications are initiated by registering a service worker with

navigator.serviceWorker.register

this works correctly

The subscrition to push notifications with

ServiceWorkerRegistration.pushManager.subscribe({
   userVisibleOnly: true,
  applicationServerKey: urlBase64ToUint8Array(_publicKey),

causes the exception AbortError Registration failed - push service error

Before the subscription is called, a check for the permissinon is made by

if (Notification.permission === 'granted')

On the C# side there is a permission request callback which allows the notification request

private void PortalWebView_PermissionRequested(object sender, CoreWebView2PermissionRequestedEventArgs e)
{
  var def = e.GetDeferral();
  e.State = CoreWebView2PermissionState.Allow;
  e.Handled = true;
  def.Complete();
}

I have reset all permissions to default when the page is loaded by

await portalWebView.CoreWebView2.Profile.SetPermissionStateAsync(CoreWebView2PermissionKind.Camera, m_portalUrl, @CoreWebView2PermissionState.Default);
await portalWebView.CoreWebView2.Profile.SetPermissionStateAsync(CoreWebView2PermissionKind.Microphone, m_portalUrl, @CoreWebView2PermissionState.Default);
await portalWebView.CoreWebView2.Profile.SetPermissionStateAsync(CoreWebView2PermissionKind.Notifications, m_portalUrl, @CoreWebView2PermissionState.Default);

If the permissions are set as e.State = CoreWebView2PermissionState.Default; no popup asking the user for notification permission is displayed (for camera and mic permissions a popup is shown).

I assume, that the allowance of the notification permission by code does not work correctly since no popup is displayed and no user interaction is requested (the Edge browser does not show a popup neither, the notification permission must be set here interactively to make the web site work)

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

1.0.2957.106

SDK Version

1.0.2957.106

Framework

Winforms

Operating System

Windows 11

OS Version

26100.2894

Repro steps

Please see descritpion under "What happened".
The web site which is called is https://test.mypoi3d.com.
The notification is initiated after a login (if needed i can create one for you)

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

No, this never worked

Last working version (if regression)

No response

@brendrch brendrch added the bug Something isn't working label Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant