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

Add support for HTML5 Notification API #308

Closed
dstaley opened this issue Jun 27, 2020 · 53 comments
Closed

Add support for HTML5 Notification API #308

dstaley opened this issue Jun 27, 2020 · 53 comments
Assignees
Labels
Awaiting release dev work has been done and in release pipeline. feature request feature request tracked We are tracking this work internally.

Comments

@dstaley
Copy link

dstaley commented Jun 27, 2020

It would be really nice if WebView2 had appropriate APIs to handle granting notification permissions and displaying notifications from web content that uses the standard Notifications API.

AB#27693296

@pagoe-msft
Copy link

@dstaley - thanks for the feature request! This something we have in the works, I will return to this thread when we have more clarity on when this feature will be completed.

@peakpeak-github
Copy link

@dstaley - thanks for the feature request! This something we have in the works, I will return to this thread when we have more clarity on when this feature will be completed.

This was 3 months ago. Any news on the issue?

@yuvdev
Copy link

yuvdev commented Oct 14, 2020

Still waiting

@champnic
Copy link
Member

Sorry for the delay!

Would the PermissionRequested event work for you scenario?

@yuvdev
Copy link

yuvdev commented Oct 15, 2020

PermissionRequested not working at all, i implemented client from that tutorial:
https://codelabs.developers.google.com/codelabs/push-notifications/#0
all works fine in Edge (86.0.622.38)
but i got
"DOMException: Registration failed - permission denied" when i tried to enable push notifications.
"TypeError: Failed to execute 'showNotification' on 'ServiceWorkerRegistration': No notification permission has been granted for this origin." when i try to push message.

I'm using "Microsoft.Web.WebView2" version="0.9.579-prerelease" targetFramework="net472"
for WPF

Version 0.9.628-prerelease not work at all.

@champnic
Copy link
Member

Are you not getting the PermissionRequested event firing on the WebView? Can you link what part of that tutorial you are using for permission registration?

@tomhoh
Copy link

tomhoh commented Mar 9, 2021

Any updates or timeline?

@minecraftchest1
Copy link

I don't know if this is important to this, but I can't get the permissionRequested even to fire using C# and WPF. It builds fine but doesn't run so I can't see what difference that makes. No errors are shown during runtime.

@tomhoh
Copy link

tomhoh commented Mar 11, 2021 via email

@Deutschi
Copy link

If I understand correctly, you basically removed this feature with version 0.8.314 https://docs.microsoft.com/en-us/microsoft-edge/webview2/release-notes#08314

Updated Notification Change Behavior so WebView2 automatically rejects notification permission requests prompted by web content hosted in the WebView.

This issue is now close to its 1-year anniversary. Are there any updates?

@DogFoxX
Copy link

DogFoxX commented Jun 20, 2021

Anyone getting this to work? I've tried

webView21.CoreWebView2.PermissionRequested += CoreWebView2_PermissionRequested;

private void CoreWebView2_PermissionRequested(object sender, Microsoft.Web.WebView2.Core.CoreWebView2PermissionRequestedEventArgs e)
{
    e.State = CoreWebView2PermissionState.Allow;
}

But when I try to run my app, it throws an exception: Object reference not set to an instance of an object.

@tomhoh
Copy link

tomhoh commented Jun 21, 2021 via email

@DogFoxX
Copy link

DogFoxX commented Jun 21, 2021

Got it working with this code I got from another issue, can't seem to find it again though:

async private void InitializeWebView2()
        {
            await webView21.EnsureCoreWebView2Async();
            webView21.CoreWebView2.PermissionRequested += CoreWebView2_PermissionRequested;
        }

        private void CoreWebView2_PermissionRequested(object sender, CoreWebView2PermissionRequestedEventArgs e)
        {
            Debug.WriteLine(e.PermissionKind.ToString());
            e.State = CoreWebView2PermissionState.Allow;
        }

The event seems to fire now for any Permission Request, all except for notifications. As stated in die Documentation, Notifications are auto-rejected and no event is raised for it.
https://docs.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2permissionkind?view=webview2-dotnet-1.0.864.35#fields

Notifications 4 Indicates permission to send web notifications. This permission request is currently auto-rejected and no event is raised for it.

It's a shame this hasn't been addressed yet.

@DominicFarrington
Copy link

Also waiting on this feature; any timeline on this? A timeline would be helpful because it would help inform whether or not to implement a custom work around.

Thanks

@champnic
Copy link
Member

We don't currently have this work scheduled within the next quarter.

@koenvd
Copy link

koenvd commented Jul 27, 2021

This would also be very useful for us since currently we are using a service worker to support push notifications in our PWA.

Also not sure what would be the best custom workaround here for a WinUI3.0 app? Using the push notifications API as being used by UWP apps? (Not sure that API is available for desktop apps). Or is there another alternative that we could use?

@koenvd
Copy link

koenvd commented Jan 6, 2022

Just wondering if this still is on the radar @champnic ? Would still be awesome to have this supported ...

@champnic
Copy link
Member

champnic commented Jan 7, 2022

It's on the radar. It's not scheduled for this quarter, but if it's priority on our backlog doesn't change, then I think we would begin work next quarter. The current workaround is indeed to use the existing Windows Notifications APIs from the host app.

@jasonstephen15
Copy link
Contributor

@OkkioXavier - what do you mean by that? do you mind expanding on your app scenario that requires notifications? Are you talking about push/background notifications through WNS? Most of the stuff I've outlined is to get e2e support for HTML5 Notifications API.

@OkkioXavier
Copy link

@jasonstephen15 thanks for your reply.

Some more details:

We're implementing a line of business application which is deployed to enterprise users, it's important for our use case that user permission is not required for push notifications.

The application which we are replacing is built in WinForms and uses the NotifyIcon class to display notifications to users. User interaction is not required to display a NotifyIcon.

WebView2 already implements support for the PermissionRequested event for other HTML5 functionality such as ClipboardRead. For those events you can programmatically grant/deny permission. When permission is granted programmatically no permissions dialog is displayed to the user. Above I was asking that the existing pattern is applied to the PermissionRequested event when raised for push notifications.

Sample code for ClipboardRead:

view.CoreWebView2.PermissionRequested += (_, args) =>
{
 var uri = new Uri(args.Uri);
 
 if (args.PermissionKind == CoreWebView2PermissionKind.ClipboardRead && uri.IsTrusted(allowLocalhost))
 {
     args.State = CoreWebView2PermissionState.Allow;
 }
 else
 {
     args.State = CoreWebView2PermissionState.Default;
 }
};		

Thanks! Let me know if you need any further details

@koenvd
Copy link

koenvd commented Sep 7, 2022

Just sharing our use case @jasonstephen15 as well.

We're currently working on a WinUI3.0 desktop app embedding a Webview2 control. The web app loaded in Webview2 will register a service worker which allows to receive push messages through the Push API.

So what would be very nice to have:

  • When the app is running that the service worker can receive the notification through the Push API and show it in the OS using registration.showNotification(message). When the user clicks the notification the service worker would receive the notificationclick event and can indicate to the app to navigate to a specific page.
  • When the app is not running that the service worker is still active and would still be able to receive and show a notification through that same flow. When the user clicks the notification ideally the app would start and be able to navigate to a specific page that was sent along with the push event. Here I'm not sure if this can be done with the same notificationclick event handler (since the app is not running) or if this would need another mechanism (the protocol uri you mentioned in your flow). Also not sure if opening Edge as default when no protocol uri is specified is the best default action.
    Edge would need a URL as well to navigate to I would think? Maybe always starting the app is preferable?

All the other points you made are very valuable as well. And also in favour of being able to enable notifications without user interaction as @OkkioXavier proposed.

@jasonstephen15
Copy link
Contributor

@OkkioXavier - right, in earlier message I noted Developers want permission event to fire for notifications. I think this should be all you need to light up your scenario. Let me know if you think otherwise. Just for absolute certainty when you say 'push notifications', you mean HTML5 Notifications being raised on the native side right?

@DominicFarrington
Copy link

@jasonstephen15 Yep, exactly. I was just clarifying that when the event fires we want the existing permissions grant functionality to be maintained. Thanks for following up.

@grabinat
Copy link

grabinat commented Sep 30, 2022

@jasonstephen15

The native notification in Windows should not have any Edge/WebView branding.

This sounds like it is planned, that Edge/WebView itself will create the toast notifications showed to the user. Is this optional?

For our use case it would be important, that the WebView is providing the HTML5 Notifications payload to the app without showing any notification. Instead, we want to process the payload with our app code. And after, the toast notification would then be created by the app itself.

@wilsonmfg
Copy link

if the event allowed updating the payload and the option to set a Handled property like keypress events do that would tell the webview to not show the notification, that would be amazing.

@RyanGelinas
Copy link

Looks like's it been a few months since the last update, is this still on the roadmap? I also have an enterprise application this would be key to. I'd need to be able to programmatically allow the push and then handle notifications to the user in my code, since it will be primary operating on devices that use a custom shell, which doesn't support native windows notifications.

@champnic
Copy link
Member

I believe we have begun work on this feature - @peiche-jessica should have the latest.

@LafallaMohamed
Copy link

Hello, Is there any updates regarding this feature ?

@peiche-jessica
Copy link
Collaborator

It should be available in the next SDK release in early June. Thanks.

@amilich
Copy link

amilich commented Jun 16, 2023

Hello! @peiche-jessica would love to use this. Let me know if it's in a release yet.

@amilich
Copy link

amilich commented Jul 8, 2023

It should be available in the next SDK release in early June. Thanks.

just writing once more, let me know if it was released

@novac42 novac42 added the Awaiting release dev work has been done and in release pipeline. label Jul 14, 2023
@novac42
Copy link
Contributor

novac42 commented Jul 27, 2023

@novac42 novac42 closed this as completed Jul 27, 2023
@amilich
Copy link

amilich commented Jul 31, 2023

Amazing!

@minecraftchest1

This comment was marked as off-topic.

@Kidades

This comment was marked as off-topic.

@ddart2
Copy link

ddart2 commented Aug 25, 2023

Hi @amilich It's released as experimental API now: please check out https://learn.microsoft.com/en-us/microsoft-edge/webview2/release-notes?tabs=dotnetcsharp#experimental-features

Still not working with 1.0.1988-prerelease and 1.0.1901 release.
After setting the permission state of webview2 as 'allow' (=1),
when I try to run the 'subscribe' function of registration.pushManager, it reports an error with the following message:

"DOMException: Registration failed - push service error."

My push subscription code in PWA works well with Chrome and Edge, but it doesn't work with webview2.

@champnic
Copy link
Member

@ddart2 What runtime version are you using? You'll likely need to use Edge Canary/Dev for this to work:
https://docs.microsoft.com/en-us/microsoft-edge/webview2/how-to/set-preview-channel

@ddart2
Copy link

ddart2 commented Aug 26, 2023

@ddart2 What runtime version are you using? You'll likely need to use Edge Canary/Dev for this to work: https://docs.microsoft.com/en-us/microsoft-edge/webview2/how-to/set-preview-channel

I am using and setting environment with 118.0.2048.1 dev.
it works with new experimental interface except 'web push subscription'.
Should I set permission state at different thread through deferral method of permission request args?
Is there anyone who has succeeded in subscribing to push notification?
thanks

@YoHanGLoot
Copy link

Anyone still with this issue? It works for Edge v 118, but not for WebView2

@ngocvd
Copy link

ngocvd commented Dec 20, 2023

Still now, it is not fired.

@grabinat
Copy link

grabinat commented Jun 5, 2024

In WinUI3 WebNotifcations are still not available.
I also just tested the WinAppSDK 1.6 experimental1. But it also does not include this feature.
Is there any ETA when this will be rollout to WinUI3 - especially as WinUI3 is now the recommended native UI platform?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting release dev work has been done and in release pipeline. feature request feature request tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests