Note: Advice in this article will only work for DotNetBrowser 1.
See the corresponding article for DotNetBrowser 2 here.
Since DotNetBrowser 1.8.4 you can handle situation when a web page wants to display desktop notifications. You decide whether the web page is allowed to display notifications or not. By default, desktop notifications are suppressed.
Configuring notification handler
C#
class TestNotificationHandler : INotificationHandler { private Action<NotificationEventArgs> action; public TestNotificationHandler(Action<NotificationEventArgs> action) { this.action = action; } public void OnShowNotification(NotificationEventArgs args) { this.action(args); } };
browser.Context.NotificationService.NotificationHandler = new TestNotificationHandler((NotificationEventArgs e) => { var notification = e.Notification; //... });
VB.NET
Class TestNotificationHandler Implements INotificationHandler Private action As Action(Of NotificationEventArgs) Public Sub New(ByVal action As Action(Of NotificationEventArgs)) Me.action = action End Sub Public Sub OnShowNotification(ByVal args As NotificationEventArgs) _ Implements INotificationHandler.OnShowNotification Me.action(args) End Sub End Class
browser.Context.NotificationService.NotificationHandler = New TestNotificationHandler(Sub(ByVal e As NotificationEventArgs) Dim notification = e.Notification '... End Sub)
The Notification
object contains URL, title, message and notification type.
Call Notification.Close()
to inform DotNetBrowser that the notification has been closed.
The JavaScript code Notification.close()
can also be used to close the notification.
Configuring permission request handler
C#
class MyPermissionHandler : IPermissionHandler { private Func<PermissionRequest, PermissionStatus> func; public MyPermissionHandler(Func<PermissionRequest, PermissionStatus> func) { this.func = func; } public PermissionStatus OnRequestPermission(PermissionRequest request) { return func(request); } };
browser.PermissionHandler = new MyPermissionHandler((PermissionRequest request) => { return PermissionStatus.GRANTED; });
VB.NET
Class MyPermissionHandler Implements IPermissionHandler Private func As Func(Of PermissionRequest, PermissionStatus) Public Sub New(ByVal func As Func(Of PermissionRequest, PermissionStatus)) Me.func = func End Sub Public Function OnRequestPermission(ByVal request As PermissionRequest) As PermissionStatus _ Implements IPermissionHandler.OnRequestPermission Return func(request) End Function End Class
browser.PermissionHandler = New MyPermissionHandler(Function(ByVal request As PermissionRequest) PermissionStatus.GRANTED)