Skip to content

TTMSFNCEdgeWebBrowser

This component inherits most of its properties, events and methods from the TTMSFNCWebBrowser. This documentation will only touch the additions to the base control.

Installation

Before you can use this control some additional actions are required. These is the same installation for the TTMSFNCWebBrowser.

In case some of the functionality isn't working as expected, please make sure that the version of your DLL supports the code. Currently this is WebView2 version 1.0.1587.

Windows (Edge Chromium)

  • Edge Browser

    1. Windows 10 with automatic updates enabled has already Edge Chromium included that is used by TAdvWebBrowser/TTMSFNCWebBrowser. If you do not have automatic updates enabled or use an older version of Windows, install Edge Chromium from the following page: https://www.microsoft.com/en-us/edge

      We have tested the installation against the last known stable version. Earlier versions are not supported. Please before installing, check the version number and ask us for an update in case you are having troubles getting the browser to run. Microsoft will also push out Edge Chromium through Windows Updates.

    2. Make sure the WebView2Loader_x86.dll and WebView2Loader_x64.dll are copied under System32 and SysWow64 folders. The dlls can be found after installation in the source directory under the folder "Edge Support". Please note that these dlls are also necessary when deploying your application!

  • Edge WebView 2

Alternatively, when distributing your application, there are a few ways you can ensure the WebView2 Runtime is on client machines. More information can be found on the following page: https://developer.microsoft.com/en-us/microsoft-edge/webview2/

Start the IDE and drop an instance of TTMSFNCWebBrowser on the form. The border around the webbrowser at designtime is for moving/selecting it. The blue box indicating the Edge Chromium is initialized, is interactable and is a live browser instance. You should see the following when the browser is successfully initialized:

Webbrowser

Manipulating the Context Menu

It is possible to change the context menu that is shown in the web browser.

  • By default it will show the menu that is generated by the browser.

  • You can change it to a framework specific menu by assigning a TPopupMenu to the EdgeWebBrowser's PopupMenu property.

  • It is also possible to have this TPopupMenu rendered as a native context menu by enabling the UsePopupMenuAsContextMenu property in Settings. The assigned events or actions when a click happens, will still be triggered.

  • You can fully customize the native context menu with the use of the event OnGetContextMenu. This event is triggered when the context menu is rendered. It has a target item (TTMSFNCWebBrowserTargetItem) that shows whether it is shown on a Page, Image, Selected Text, Audio or Video. And you can check if there is a link or selected text attached to it. Based on this you can now choose which items to show in the context menu. In this event there is a list of TTMSFNCWebBrowserContextMenuItem. You will notice that it is not possible to get any information, because the system generated items are protected. Only custom items can be changed. To help you with this the AsSystem and AsCustom functions are available. You can delete system items from the list. But the position can't be changed. TTMSFNCWebBrowserCustomContextMenuItem items can be created and inserted in the list.

It is only possible to detect if an item was clicked with custom items. If you want to have full control over the context menu, we advise to use a popup menu or recreate all of the items.

procedure TForm.EdgeWebBrowserGetContextMenu(Sender: TObject; ATarget: TTMSFNCWebBrowserTargetItem; AContextMenu: TObjectList<TTMSFNCWebBrowserContextMenuItem>);
var
  I: Integer;
  mi: TTMSFNCWebBrowserCustomContextMenuItem;
begin
  if ATarget.Kind = mtSelectedText then
    SelectionEdit.Text := ATarget.SelectionText;

  //Make sure the customer can't reload the page from the context menu
  while I < AContextMenu.Count do
  begin
    if AContextMenu[I].AsSystem.Name.ToLower <> 'reload' then
      AContextMenu.Delete(I);
    Inc(I);
  end;

  mi := TTMSFNCWebBrowserCustomContextMenuItem.Create;
  mi.Name := 'Go to TMS';

  AContextMenu.Insert(0, mi);
end;

procedure TForm.TMSFNCEdgeWebBrowserCustomContextMenuItemSelected(Sender: TObject; ASelectedItem: TTMSFNCWebBrowserCustomContextMenuItem);
var
  s: string;
begin
  if ASelectedItem.AsCustom.Name = 'Go to TMS' then
  begin
    TMSFNCEdgeWebBrowser.Navigate('https://www.tmssoftware.com');
  end;
end;

DevTools Methods and Events

The Chrome DevTools Protocol provides APIs to instrument, inspect, debug, and profile Chromium-based browsers. The Chrome DevTools Protocol is the foundation for the Microsoft Edge DevTools. Use the Chrome DevTools Protocol for features that aren't implemented in the TMSFNCEdgeWebBrowser.

  • Methods can be called with CallDevToolsProtocolMethod and the response to it is retrieved with OnDevToolsMethodCompleted as a json string.
  • Events should be registered first with SubscribeDevtools (the enable method is called by default). After registration the events trigger the OnDevToolsSubscribedEvent.

  • By default the events Log.entryAdded and Runtime.consoleAPICalled are already parsed in OnGetConsoleMessage.

Properties

Property name Description
Settings Object of TTMSFNCWebBrowserSettings to configure your web browser in design time.
URL The address of the current webpage of the browser.
Downloads List of all the downloads that were starting since initialization.

Settings

Property name Description
AdditionalBrowserParameters A Stringlist of different startup parameters that is used when creating the web browser. (WebView2 will skip any that is conflicting with its internal workings.)
EnableAcceleratorKeys Boolean that indicates whether all accelerator keys that access features specific to a web browser are enabled.
EnableContextMenu Boolean that indicates whether it is possible to show the context menu.
EnableShowDebugConsole Boolean that indicates whether it is possible to show the debug console.
Language The localization that is used when creating the web browser.
UsePopupMenuAsContextMenu Boolean that indicates whether an assigned popup menu should be shown as the native context menu.

Methods

Method name Description
OpenTaskManager Opens the Browser Task Manager view as a new window in the foreground.
GetCookies(AURI: string) Gets a list of cookies, if a URI was spacified then it will only show those that match the specific URI.
AddCookie(ACookie: TTMSFNCWebBrowserCookie) Adds or updates a cookie with the given cookie data; may overwrite cookies with matching name, domain, and path if they exist.
DeleteAllCookies Deletes all cookies under the same profile.
DeleteCookie(AName, ADomain, APath: string) Deletes a cookie whose name and domain/path pair match those of the specified cookie.
ShowPrintUI(ACookie: TTMSFNCWebBrowserCookie) Opens the print dialog to print the current web page.
InitialPrintSettings Returns TTMSFNCWebBrowserPrintSettings with default values.
Print(APrintSettings: TTMSFNCWebBrowserPrintSettings) Print the current web page asynchronously to the specified printer with the default or provided settings.
PrintToPDFStream(APrintSettings: TTMSFNCWebBrowserPrintSettings) Provides the PDF data of current web page asynchronously for the default or provided settings.
PrintToPDF(AFileName: string; APrintSettings: TTMSFNCWebBrowserPrintSettings) Print the current page to PDF asynchronously with the default or provided settings.
NavigateWithData(AURI: string; AMethod: string; ABody: string; AHeaders: TStrings) Navigates to an URI with a custom method and data as text.
NavigateWithData(AURI: string; AMethod: string; ABodyStream: TStream; AHeaders: TStrings) Navigates to an URI with a custom method and data as a stream.
CallDevToolsProtocolMethod(AMethodName: string; AParametersAsJSON: string) Runs an asynchronous DevToolsProtocol method.
SubscribeDevtools(AEventName: string) Subscribe to an event via the name to receive them in OnDevToolsSubscribedEvent.

Events

Event name Description
OnGetCookies Returns an array of TTMSFNCWebBrowserCookie after retrieving the cookies from the method GetCookies.
OnPrinted Returns a boolean to indicate if the method Print was successful.
OnPrintedToPDF Returns a boolean to indicate if the method PrintToPDF was successful.
OnGetPrintPDFStream Returns a TMemoryStream after converting the webpage to a PDF with the method PrintToPDFStream.
OnGetContextMenu Triggered when the context menu is shown. You can check what to handle with TTMSFNCWebBrowserTargetItem and you can manipulate the items with the list of TTMSFNCWebBrowserContextMenuItem
OnGetPopupMenuForContextMenu Choose the popup menu to be used in the context menu.
OnCustomContextMenuItemSelected Returns a TTMSFNCWebBrowserCustomContextMenuItem when a custom item was selected in the context menu.
OnCustomContextMenuItemSelected Returns a TTMSFNCWebBrowserCustomContextMenuItem when a custom item was selected in the context menu.
OnDevToolsMethodCompleted Returns the json response of the CallDevToolsProtocolMethod.
OnDevToolsSubscribedEvent Returns the json message of the registered events with SubscribeDevtools.
OnGetConsoleMessage Triggered when there are new entries in the console.
OnDownloadStarted Triggered when a new download will be started. You can set the result path and choose if the download should be silent, paused or cancelled.
OnDownloadStateChanged Triggered when the state of a download was changed.
OnDownloadBytesReceivedChanged Periodically triggered with an update of the downloads progress.