Hello:
In my project, I have to login to one web page, and after login, I want to disable JavaScript, as it has some JavaScript to logout automatically after 30 minutes, no mater what you are doing in the page, even if you are trying to click on some buttons, but it logs you out and you have to login again by typing user name and password.
So I want to add one button to disable the JavaScript on the page after I login, but login take some time, as it may involve resolving some Captcha challenges, so I can click the button after I have successfully logged in.
I created one Windows Form App (.NET) for target .Net 5.0; install WebView2 nuget package:
Install-Package Microsoft.Web.WebView2 -Version 1.0.705.50
I have the following code: (IDE: VS2019 Version 16.8.4)
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.WinForms;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WebView2Buttons
{
public partial class Form1 : Form
{
private readonly WebView2 BingWebView = new WebView2();
private readonly Button Button1 = new Button();
private async void Button1_Click(object sender, EventArgs e)
{
// How I can set CoreWebView2Settings.IsScriptEnabled to false?
}
public Form1()
{
InitializeComponent();
BingWebView.CreationProperties = null;
BingWebView.Location = new Point(10, 100);
BingWebView.Name = "BingWebView";
BingWebView.Size = new Size(1700, 700);
BingWebView.Source = new Uri("https://www.bing.com/", UriKind.Absolute);
BingWebView.TabIndex = 0;
BingWebView.ZoomFactor = 1D;
BingWebView.Visible = true;
Controls.Add(BingWebView);
this.SuspendLayout();
ClientSize = new Size(1800, 800);
Button1.Location = new Point(50, 10);
Button1.Name = "Button1";
Button1.Size = new Size(250, 50);
Button1.TabIndex = 2;
Button1.Text = "Button1";
Button1.UseVisualStyleBackColor = true;
Button1.Click += new EventHandler(Button1_Click);
Controls.Add(Button1);
Name = "Form1";
Text = "Form1";
ResumeLayout(false);
}
private async void Form1_Load(object sender, EventArgs e)
{
}
}
}
Please advice!