Информация об изменениях

Сообщение Re[9]: WebView2 с Proxy от 16.07.2025 13:30

Изменено 16.07.2025 14:55 Passerby

Re[9]: WebView2 с Proxy
Здравствуйте, Passerby, Вы писали:

P>Здравствуйте, Passerby, Вы писали:


P>>Здравствуйте, bnk, Вы писали:


bnk>>>У меня он работает без прокси

P>>Кто провайдер?

bnk>>>Ну я и говорю, ты уже где-то инициализируешь его до Form_Load (ставишь Source?)

P>>Нет, Source не ставлю.
bnk>>>Ты сделал как написано выше, по шагам (1, 2)?
P>>Сделал снова.
P>>Новое приложение Form от Microsoft. Или нужен с FrameWork? Net 9.0.
P>>Установил в NuGet WebView2.
P>>Дополнил конструктор Form1.
P>>К событию Load подсоединил метод Form1_Load(object sender, EventArgs e).
P>>Запустил отладку, ошибка на строке await myWebView2.EnsureCoreWebView2Async(env);
P>>
P>>using Microsoft.Web.WebView2.Core;
P>>//using Microsoft.Web.WebView2.WinForms;
P>>namespace WinFormsApp1
P>>{
P>>    public partial class Form1 : Form
P>>    {
P>>        //private readonly WebView2 myWebView2 = new WebView2(); уже есть определение
P>>        public Form1()
P>>        {
P>>            InitializeComponent();
P>>            myWebView2.CreationProperties = null;
P>>            myWebView2.Location = new Point(10, 65);
P>>            myWebView2.Name = "myWebView2";
P>>            myWebView2.Size = new Size(1750, 780);
P>>            myWebView2.Source = new Uri("https://www.bing.com/", UriKind.Absolute);
P>>            myWebView2.TabIndex = 0;
P>>            myWebView2.ZoomFactor = 1D;
P>>            myWebView2.Visible = true;
P>>            this.SuspendLayout();
P>>            ClientSize = new Size(1800, 800);
P>>            Controls.Add(myWebView2);
P>>            Name = "Form1";
P>>            Text = "Form1";
P>>            ResumeLayout(false);
P>>        }
P>>        private async void Form1_Load(object sender, EventArgs e)
P>>        {
P>>            CoreWebView2EnvironmentOptions Options = new CoreWebView2EnvironmentOptions();
P>>            Options.AdditionalBrowserArguments = "--proxy-server=http://1.2.3.4:8888";
P>>            CoreWebView2Environment env =
P>>                await CoreWebView2Environment.CreateAsync(null, null, Options);
P>>            await myWebView2.EnsureCoreWebView2Async(env);
P>>        }
P>>    }
P>>}
P>>

P>>
P>>namespace WinFormsApp1
P>>{
P>>    partial class Form1
P>>    {
P>>        /// <summary>
P>>        ///  Required designer variable.
P>>        /// </summary>
P>>        private System.ComponentModel.IContainer components = null;

P>>        /// <summary>
P>>        ///  Clean up any resources being used.
P>>        /// </summary>
P>>        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
P>>        protected override void Dispose(bool disposing)
P>>        {
P>>            if (disposing && (components != null))
P>>            {
P>>                components.Dispose();
P>>            }
P>>            base.Dispose(disposing);
P>>        }

P>>        #region Windows Form Designer generated code

P>>        /// <summary>
P>>        ///  Required method for Designer support - do not modify
P>>        ///  the contents of this method with the code editor.
P>>        /// </summary>
P>>        private void InitializeComponent()
P>>        {
P>>            myWebView2 = new Microsoft.Web.WebView2.WinForms.WebView2();
P>>            ((System.ComponentModel.ISupportInitialize)myWebView2).BeginInit();
P>>            SuspendLayout();
P>>            // 
P>>            // webView21
P>>            // 
P>>            myWebView2.AllowExternalDrop = true;
P>>            myWebView2.CreationProperties = null;
P>>            myWebView2.DefaultBackgroundColor = Color.White;
P>>            myWebView2.Location = new Point(12, 52);
P>>            myWebView2.Name = "myWebView2";
P>>            myWebView2.Size = new Size(776, 372);
P>>            myWebView2.TabIndex = 0;
P>>            myWebView2.ZoomFactor = 1D;
P>>            // 
P>>            // Form1
P>>            // 
P>>            AutoScaleDimensions = new SizeF(7F, 15F);
P>>            AutoScaleMode = AutoScaleMode.Font;
P>>            ClientSize = new Size(800, 450);
P>>            Controls.Add(myWebView2);
P>>            Name = "Form1";
P>>            Text = "Form1";
P>>            Load += Form1_Load;
P>>            ((System.ComponentModel.ISupportInitialize)myWebView2).EndInit();
P>>            ResumeLayout(false);
P>>        }

P>>        #endregion

P>>        private Microsoft.Web.WebView2.WinForms.WebView2 myWebView2;
P>>    }
P>>}
P>>


И непонятно, зачем вынесено в конструктор Form1 строки, которые есть в InitializeComponent(); Можно их оставить либо в конструкторе, либо в InitializeComponent().
Re[9]: WebView2 с Proxy
Здравствуйте, Passerby, Вы писали:

bnk>>>У меня он работает без прокси

Кто провайдер?

bnk>>>Ну я и говорю, ты уже где-то инициализируешь его до Form_Load (ставишь Source?)

Нет, Source не ставлю.
bnk>>>Ты сделал как написано выше, по шагам (1, 2)?
Сделал снова.
Новое приложение Form от Microsoft. Или нужен с FrameWork? Net 9.0.
Установил в NuGet WebView2.
Дополнил конструктор Form1.
К событию Load подсоединил метод Form1_Load(object sender, EventArgs e).
Запустил отладку, ошибка на строке await myWebView2.EnsureCoreWebView2Async(env);
using Microsoft.Web.WebView2.Core;
//using Microsoft.Web.WebView2.WinForms;
namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        //private readonly WebView2 myWebView2 = new WebView2(); уже есть определение
        public Form1()
        {
            InitializeComponent();
            myWebView2.CreationProperties = null;
            myWebView2.Location = new Point(10, 65);
            myWebView2.Name = "myWebView2";
            myWebView2.Size = new Size(1750, 780);
            myWebView2.Source = new Uri("https://www.bing.com/", UriKind.Absolute);
            myWebView2.TabIndex = 0;
            myWebView2.ZoomFactor = 1D;
            myWebView2.Visible = true;
            this.SuspendLayout();
            ClientSize = new Size(1800, 800);
            Controls.Add(myWebView2);
            Name = "Form1";
            Text = "Form1";
            ResumeLayout(false);
        }
        private async void Form1_Load(object sender, EventArgs e)
        {
            CoreWebView2EnvironmentOptions Options = new CoreWebView2EnvironmentOptions();
            Options.AdditionalBrowserArguments = "--proxy-server=http://1.2.3.4:8888";
            CoreWebView2Environment env =
                await CoreWebView2Environment.CreateAsync(null, null, Options);
            await myWebView2.EnsureCoreWebView2Async(env);
        }
    }
}

namespace WinFormsApp1
{
    partial class Form1
    {
        /// <summary>
        ///  Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
        /// <summary>
        ///  Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
        #region Windows Form Designer generated code

        /// <summary>
        ///  Required method for Designer support - do not modify
        ///  the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            myWebView2 = new Microsoft.Web.WebView2.WinForms.WebView2();
            ((System.ComponentModel.ISupportInitialize)myWebView2).BeginInit();
            SuspendLayout();
            // 
            // webView21
            // 
            myWebView2.AllowExternalDrop = true;
            myWebView2.CreationProperties = null;
            myWebView2.DefaultBackgroundColor = Color.White;
            myWebView2.Location = new Point(12, 52);
            myWebView2.Name = "myWebView2";
            myWebView2.Size = new Size(776, 372);
            myWebView2.TabIndex = 0;
            myWebView2.ZoomFactor = 1D;
            // 
            // Form1
            // 
            AutoScaleDimensions = new SizeF(7F, 15F);
            AutoScaleMode = AutoScaleMode.Font;
            ClientSize = new Size(800, 450);
            Controls.Add(myWebView2);
            Name = "Form1";
            Text = "Form1";
            Load += Form1_Load;
            ((System.ComponentModel.ISupportInitialize)myWebView2).EndInit();
            ResumeLayout(false);
        }

        #endregion

        private Microsoft.Web.WebView2.WinForms.WebView2 myWebView2;
    }
}


И непонятно, зачем вынесено в конструктор Form1 строки, которые есть в InitializeComponent(); Можно их оставить либо в конструкторе, либо в InitializeComponent().