Is there a way to disable Browser notifications in WebView2 - c#

Im building a WPF app and i'm trying to check several URL's in the background within a WebView2 window
Altough some urls have popups (which aren't real popups) in the upper left corner like asking for permission to use e.g. the microphone or something.
These popups are getting displayed in full size even if the visibility of the 1x1 pixel big webview is hidden
Here is an example of such a popup in my app:
The black corner is the edge of the app and as you can see the meet.google.com popup is displayed in full size even if the webview is invisible
I already tried to disable the notifications with the new window requested event but this doesn't work because it isn't a new window and it doesn't have a URL or anything.
I also tested many CoreWebView2 settings which made sense,like before no useful results
Does somebody know if there is a setting or something which i have to enable/disable in WebView2 to disable these notifications?
If any further information is required please ask me!

You need to look at the Permissions Requested event for mic and camera.
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;
}

Related

Windows notification created with NotifyIcon shows "microsoft.explorer.notification" and GUID

We have written a WPF desktop application for Windows. The application launches on start-up and mostly runs in the background, but has a UI which is accessible via the system tray. Occasionally the app needs to notify the user of something, and so for this, we use the NotifyIcon library to generate notifications. Here is the relevant code:
XAML:
<mui:ModernWindow
...
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tb="http://www.hardcodet.net/taskbar"
... >
<tb:TaskbarIcon
x:Name="MyAppIcon"
...
</tb:TaskbarIcon>
</mui:ModernWindow>
C# code behind:
using Hardcodet.Wpf.TaskbarNotification
public void ShowStartupBalloon(string message)
{
// show balloon with built-in icon ie 'Info'
MyAppIcon.ShowBalloonTip(Properties.Resources.App_Title, message, BalloonIcon.Info);
}
The notifications appear as small floating windows near the taskbar, but (sometimes, not always) they include the string "microsoft.explorer.notification" and GUID.
We would like to eliminate these as they are confusing our customers; many think some kind of error in the software has occurred. Does anyone know how to suppress that in order to display only the text of the notification we have supplied?
I've experienced this problem as well. From what I've gathered, that bottom text is Microsoft's way of making sure that a user knows the source of a notification, and that random programs can't impersonate a genuine windows notification. The inclusion of a ToolTipIcon (in your case the info icon) seems to trigger this.
As a result, you can remove that text completely by not specifying a BalloonTipIcon, either by not defining the property at all, or defining it as None:
MyAppIcon.ShowBalloonTip(Properties.Resources.App_Title, message, BalloonIcon.None);
The only tradeoff, of course, is that your notification won't have an icon.
Hope this helps.
Show icon with automatic timeout:
public static void ShowBalloon(string title, string body)
{
// Show with icon
NotifyIcon ni = new NotifyIcon() { Visible = true, Icon = Properties.Resources.Icon};
// Timeout is deprecated since Vista
ni.ShowBalloonTip(0, title, body, ToolTipIcon.None);
// Dispose on event
ni.BalloonTipClosed += (sender, e) => ni.Dispose();
}
Microsoft.Explorer.Notification text is shown due to immediate disposal of NotifyIcon object.
So basically if you call
MyAppIcon.ShowBalloonTip(5000);
MyAppIcon.Dispose();
you get the Microsoft.Explorer.Notification.{GUID} instead of AppName in the notification title.
To fix that avoid direct disposal and use what Beni proposed:
MyAppIcon.BalloonTipClosed += (sender, e) => MyAppIcon.Dispose();

Windows 8.1 Tabs & Windows with webview

When navigating using the webview in a Windows Store app any links which try to open in a new tab/windows or opened in internet explorer thus practically pulling users from my app. is there any way to handle the link event to either force the links to open in current view or a way to run code to create a new tab within my own app. i have had a look around and can't seem to see much in the way of a defined way of doing this.
You can hook up to the WebViews "NavigationStarting" event.
The you can cancel the navigation and reissue it from within your code so it navigates inside the webview.
Xaml:
<WebView NavigationStarting="WebView_NavigationStarting" />
Codebehind:
private void WebView_NavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args)
{
if (args.Uri != null)
{
args.Cancel = true;
sender.Navigate(args.Uri);
}
}
But you will loose the ability to open links in new windows completely, as you only have the uri itself available in the event handler.
Uri will be null if you use the NavigateToString operations on the webview.

Display window over full screen application

I'm working on a .Net (WPF/C#) application, the application displays notifications (similar to Growl notifications on OS X) at different times, I would like the notifications to display above all other windows, including when there is a full screened app (like a PowerPoint presentation).
Is there anyway to display a Window over a full screened app?
Did you try to set TopMost = true parameter of this window?
also check this thread:
Form top most?
or you can use Popup instead, it will on top of any window or control.
WPF.
private void Window_Deactivated(object sender, EventArgs e)
{
Thread.Sleep(2000);
this.Topmost = true;
}
But this is not the best option.
In full screen mode there is exclusive access to the display, and you can only display on top of this if you are allowed to implement it if it's a game in OpenGL, DirectX and BackBuffer to impose your data.

Capture and save multiple images with `CameraCaptureDialog`

I have a Windows Mobile (Compact framework 2) application that defines a user control MPhotoControl. MPhotoControl shows a default image and when the user clicks on this image a CameraCaptureDialog is opened to allow a photo to be captured. Once captured, the photo is then displayed in the user control. This works fine for capturing a single photo and then going back to the application.
The problem is that when there are lots of these controls on a particular form then the user interface becomes very unfriendly because the user has to show the camera dialog, take a photo, save and close the dialog for every photo control on the form. What the users are asking for is a mechanism to open the CameraCaptureDialog, take several photos without the dialog closing until all the photo controls have images.
I am trying to implement this, but I don't see a way to get the CameraCaptureDialog to capture and save several photos at once. As far as I can tell it is not possible, because when the dialog shows on my HTC Touch Diamond, I only have the options to "Accept the photo" (arrow icon), "Capture again" (camera icon) or "cancel and close dialog" (dustbin icon). And when I click the arrow to accept it always closes the dialog box.
So does anyone know of a way of capturing and saving more than one image at a time using CameraCaptureDialog?
I then thought of trying to open the CameraCaptureDialog multiple times as a work around. So as soon as the first image is saved the dialog is immediately opened again to capture the second image. Here is my code showing my attempt at a workaround:
public partial class MPhotoControl : UserControl
{
public static IEnumerable<MPhotoControl> PhotoControls;
...
private void CaptureMultiplePhotos()
{
foreach (MPhotoControl photo in PhotoControls)
{
using (CameraCaptureDialog cameraDialog = new CameraCaptureDialog())
{
if (cameraDialog.ShowDialog() != DialogResult.OK)
{
break;
}
photo.CapturePhoto(cameraDialog.FileName);
}
}
}
}
The problem with this is that the CameraCaptureDialog still only opens once and the subsequent call to the ShowDialog method simply returns DialogResult.Cancel. So, does anyone know why this workaround does not work and if it is possible to get the dialog to immediately re-open once the previous captured image has been saved?
Please look here: http://www.hjgode.de/wp/2012/10/17/windows-mobile-cameracapturedialog-alternative/
I am unable to attach any code or binaries here, so I did a new blog post.
The code start the camera app, waits for its close-down and presents you with a list of new photos.
Code is not yet perfect but a starting point.

Creating a Popup Balloon like Windows Messenger or AVG

How can I create a Popup balloon like you would see from Windows Messenger or AVG or Norton or whomever?
I want it to show the information, and then slide away after a few seconds.
Edit: It needs to be blocking like Form.ShowDialog() because the program exits after displaying the notification
You can use the notifyIcon control that's part of .NET 2.0 System.Windows.Forms. That allows you to place an icon for your application in the System Tray. Then, you can call the ShowBalloonTip(int timeOut) method on that. Be sure however to first set the text, and icon properties on the notifyIcon for it to work. Small code sample:
private void button1_Click(object sender, EventArgs e)
{
this.notifyIcon1.BalloonTipText = "Whatever";
this.notifyIcon1.BalloonTipTitle = "Title";
this.notifyIcon1.Icon = new Icon("icon.ico");
this.notifyIcon1.Visible = true;
this.notifyIcon1.ShowBalloonTip(3);
}
EDIT: Ok, so notifyIcon won't work for you. My second suggestion would then be to create your own control for this. Actually, I would use a form. A simple form, with no borders, and no control box and just have a timer running so you can set the Opacity for fade in/out. Then, you can easily get the bottom right of the screen using the Rectangle Screen.PrimaryScreen.WorkingArea. Then just show your form at that position.
Don't create a modal (blocking) balloon. Please. A big part of the design of these UIs is that they are not dialogs: they're transient, potentially non-interactive elements, intended to provide incidental information to a user without necessarily interrupting their workflow. A balloon that steals focus and blocks user input would be irritating at best - if you need a dialog, then use a dialog.
The .NET 1.1 Visual Basic Power Pack had a toaster control.

Categories