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

.NET MAUI Blazory hybrid .AddBlazorWebViewDeveloperTools() Issue #20859

Closed
DavorBeg opened this issue Feb 27, 2024 · 4 comments
Closed

.NET MAUI Blazory hybrid .AddBlazorWebViewDeveloperTools() Issue #20859

DavorBeg opened this issue Feb 27, 2024 · 4 comments
Labels
area-blazor Blazor Hybrid / Desktop, BlazorWebView platform/windows 🪟 s/needs-attention Issue has more information and needs another look t/bug Something isn't working

Comments

@DavorBeg
Copy link

Description

Last week on date:
(EU date format): 23.02.2024 (Friday)
In my MAUI Blazor application, F12 developer tool was working perfect.
I finished work, left my windows to update and yesterday F12 didnt want to open anymore.

#if DEBUG
            builder.Services.AddBlazorWebViewDeveloperTools();
            builder.Logging.AddDebug();
#endif

Just to mention what I tried to make it work again:

  1. Code above was always inside my MauiProgram.cs
  2. Tried to move it outside of #IF DEBUG
  3. Tried running my app on different environments
  4. Tried to revert windows update
  5. Deleted some temp files for visual studio
  6. Deleted all files from AppData/Local/Temp
  7. Cleaned my solution several times.
  8. Deleted bin .vs and obj folders inside my project
  9. Tried to disable some services from DI inside my app

Steps to Reproduce

  1. Create .NET MAUI Blazor app
  2. Open MainPage.xaml.cs file
  3. Add next code to:
	public partial class MainPage : ContentPage
	{
		public MainPage()
		{
			InitializeComponent();
			Loaded += WebViewLoadedEvent;
		}

		private async void WebViewLoadedEvent(object? sender, EventArgs e)
		{
			if (blazorWebView is not null && blazorWebView.Handler is not null)
			{
				var view = (blazorWebView.Handler.PlatformView as Microsoft.UI.Xaml.Controls.WebView2);
				await view!.EnsureCoreWebView2Async();

				var settings = view.CoreWebView2.Settings;
				settings.IsZoomControlEnabled = false;
				settings.AreBrowserAcceleratorKeysEnabled = false;

			}

		}
	}
  1. Run application and try to press F12, it should not work.

Link to public reproduction project repository

No response

Version with bug

8.0.6 SR1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.6 SR1

Affected platforms

Windows

Affected platform versions

Windows 10.0.19041.0

Did you find any workaround?

	public partial class MainPage : ContentPage
	{
		public MainPage()
		{
			InitializeComponent();
			Loaded += WebViewLoadedEvent;
		}

		private async void WebViewLoadedEvent(object? sender, EventArgs e)
		{
			if (blazorWebView is not null && blazorWebView.Handler is not null)
			{
				var view = (blazorWebView.Handler.PlatformView as Microsoft.UI.Xaml.Controls.WebView2);
				await view!.EnsureCoreWebView2Async();

				var settings = view.CoreWebView2.Settings;
				settings.IsZoomControlEnabled = false;
				settings.AreBrowserAcceleratorKeysEnabled = false;

			}

		}
	}

This code is copied from stackoverflow (not 100% sure), and it worked until now.
I am using it to disable zoom in/out webview inside my app and to disable functions like 'CTRL + F'. Check it on: Documentation

Solution:

  1. Delete this line of code: settings.AreBrowserAcceleratorKeysEnabled = false;
  2. Put settings.AreBrowserAcceleratorKeysEnabled = false; inside #IF !DEBUG

I am using 2. solution, because settings.AreBrowserAcceleratorKeysEnabled = false; is working, and will disable functions like its written inside docs, but... It will also disable F12 and block you to open dev tools, even if you have .AddBlazorWebViewDeveloperTools() inside MauiProgram.cs

Relevant log output

No response

@DavorBeg DavorBeg added the t/bug Something isn't working label Feb 27, 2024
@jfversluis jfversluis added the area-blazor Blazor Hybrid / Desktop, BlazorWebView label Feb 27, 2024
@drasticactions
Copy link
Contributor

You're disabling accelerator keys, and that includes F12

スクリーンショット 2024-02-27 23 33 18

So F12 works again when you move "settings.AreBrowserAcceleratorKeysEnabled = false;" to only be invoked in non-Debug builds. I'm not sure how this is a bug, that seems correct.

@drasticactions drasticactions added the s/needs-info Issue needs more info from the author label Feb 27, 2024
@ghost
Copy link

ghost commented Feb 27, 2024

Hi @DavorBeg. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@DavorBeg
Copy link
Author

DavorBeg commented Feb 27, 2024

@drasticactions Hmm yes... This is my bad for not reading docs 😐, but still its funny how it was working without any problem last week or even 1 month ago. Because this code that I pasted is inside my app from start of the project and I didn't have ever any problem with opening F12. It just stopped working randomly ( started working ).
I checked my repository history and no changes was made in that file for long time, and no one is working on this project except me.
I checked Edge info about updates, there was some update on 23.February.2024 which maybe fixed this unknown behavior. Edge updates
Correct me if I am wrong with my theory and thanks for pointing solution that I missed in documentation, I appreciate it.

Update:
Checked my code written back on 8.January.2024 :

	public partial class MainPage : ContentPage
	{
		public MainPage()
		{
			InitializeComponent();
			Loaded += WebViewLoadedEvent;
		}

		private async void WebViewLoadedEvent(object? sender, EventArgs e)
		{
			if(blazorWebView is not null && blazorWebView.Handler is not null)
			{
				var view = (blazorWebView.Handler.PlatformView as Microsoft.UI.Xaml.Controls.WebView2);
				await view!.EnsureCoreWebView2Async();

				
				var settings = view.CoreWebView2.Settings;
				settings.IsZoomControlEnabled = false;
				settings.AreBrowserAcceleratorKeysEnabled = false;
			}
		}
	}

And I am pretty sure F12 was working, so like I said maybe Edge was updated and it was security issue.

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Feb 27, 2024
@jfversluis
Copy link
Member

Seems we're all good here then yay! Thanks all!

@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Blazor Hybrid / Desktop, BlazorWebView platform/windows 🪟 s/needs-attention Issue has more information and needs another look t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants