user1580348
user1580348

Reputation: 6051

TEdgeBrowser does not work at all despite WebView2 installed

In my Delphi 12.1 VCL Application in Windows 11 Pro 64-bit I need a browser to render remote web pages from the Internet. So I dropped a TEdgeBrowser on my form to test it:

PAS file:

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Winapi.WebView2, Winapi.ActiveX,
  Vcl.Edge;

type
  TForm1 = class(TForm)
    EdgeBrowser1: TEdgeBrowser;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  EdgeBrowser1.Navigate('https://www.example.com');
end;

end.

DFM file:

object Form1: TForm1
  Left = 0
  Top = 0
  Margins.Left = 5
  Margins.Top = 5
  Margins.Right = 5
  Margins.Bottom = 5
  Caption = 'Form1'
  ClientHeight = 664
  ClientWidth = 938
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -18
  Font.Name = 'Segoe UI'
  Font.Style = []
  Position = poScreenCenter
  OnCreate = FormCreate
  PixelsPerInch = 144
  TextHeight = 25
  object EdgeBrowser1: TEdgeBrowser
    Left = 0
    Top = 0
    Width = 938
    Height = 664
    Margins.Left = 5
    Margins.Top = 5
    Margins.Right = 5
    Margins.Bottom = 5
    Align = alClient
    TabOrder = 0
    AllowSingleSignOnUsingOSPrimaryAccount = True
    TargetCompatibleBrowserVersion = '117.0.2045.28'
    UserDataFolder = '%LOCALAPPDATA%\bds.exe.WebView2'
    ExplicitLeft = 480
    ExplicitTop = 360
    ExplicitWidth = 150
    ExplicitHeight = 60
  end
end

I went to the Microsoft website:

https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section

and downloaded: MicrosoftEdgeWebview2Setup.exe

After running the Webview installer, it said:

Message shown after running the webview2 installer

When running my test application, it showed: Nothing!

What must I do to make this work?

Upvotes: 1

Views: 573

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 595981

Per Embarcadero's documentation:

Using TEdgeBrowser Component and Changes to the TWebBrowser Component

It is not enough to just install the WebView2 control. You also need to install the WebView2 SDK so that you can copy its WebView2Loader.dll file into your app's folder (or anywhere else on the OS search path).

You also need to configure the browser's UserDataFolder property before you navigate to any URL.

Also, you should assign an OnCreateWebViewCompleted event handler to detect failures in initializing the WebView2 control. If you don't, you need to use the TApplication(Events).OnException event instead to catch the failure.

Upvotes: 4

Related Questions