Since I can no longer call active-X from my client JavaScript as I did with TWebBrowser since 2013, I had to write a work-around. I have it working except for the Fly-Out menu that Edge throws out. I have gone into the settings and turned it off. When I use an Edge directly, that decision is respected but when I call it through the TEdgeBrowser, it always open the Downloads Menu, Asking where I want to save. My intentions are to have this be an event driven operation with no user interaction.
I've searched the registry and policies, along with ICoreWebView properties. I did find ICoreWebView2DownloadOperation and ICoreWebView2DownloadStartingEventArgs but Delphi does not expose these in Winapi.WebView2!!! Nor am I given a WebView2.TLB. If so, I would import it and create my own wrapper. From my reading:
Is it possible to modify the Winapi.WebView2 and add the ICoreWebView2DownloadStartingEventArgs interface?
get_Handled and put_Handled The host may set this flag to TRUE to hide the default download dialog for this download.
public HRESULT get_Handled(BOOL * handled)
The download will progress as normal if it is not canceled, there will just be no default UI shown. By default the value is FALSE and the default download dialog is shown. The host may set this flag to TRUE to hide the default download dialog for this download.
Sets the Handled property. public HRESULT put_Handled(BOOL handled)
The download will progress as normal if it is not canceled, there will just be no default UI shown. By default the value is FALSE and the default download dialog is shown.
My little test app:
unit MainFormU;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, System.UITypes, System.Types,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Menus, Vcl.ComCtrls, Vcl.ToolWin, Vcl.ExtCtrls,
Vcl.Edge, WebView2, Winapi.ActiveX;
type
TfrmMain = class(TForm)
MainMenu: TMainMenu;
EdgeBrowser: TEdgeBrowser;
RunHTML1: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure mniScriptClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
MyScript:TStringList;
end;
var
frmMain: TfrmMain;
implementation
uses
System.Math, System.StrUtils, System.Win.ComObj, System.IOUtils;
{$R *.dfm}
procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
MyScript.Free;
end;
procedure TfrmMain.FormCreate(Sender: TObject);
begin
EdgeBrowser.Navigate('about:blank');
MyScript := TStringList.Create;
MyScript.LoadFromFile('TextToFile.html');
end;
procedure TfrmMain.mniScriptClick(Sender: TObject);
begin
EdgeBrowser.NavigateToString(MyScript.Text);
end;
object frmMain: TfrmMain
Left = 0
Top = 0
Caption = 'Main Form'
ClientHeight = 264
ClientWidth = 598
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Tahoma'
Font.Style = []
Menu = MainMenu
Position = poDefault
OnClose = FormClose
OnCreate = FormCreate
TextHeight = 16
object EdgeBrowser: TEdgeBrowser
Left = 0
Top = 0
Width = 598
Height = 262
Align = alTop
TabOrder = 0
TabStop = True
ExplicitWidth = 633
end
object MainMenu: TMainMenu
Left = 528
Top = 32
object mniScript: TMenuItem
Caption = 'Run HTML'
OnClick = mniScriptClick
object RunHTML1: TMenuItem
Caption = 'Run HTML'
end
end
end
end
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<table>
<tr><td>Text to Save:</td></tr>
<td><button onclick="saveTextAsFile('N:34.00C, S:34.00D, E:8400C, W:8359A', 'ShowMinBounds')">Save Text to File</button></td>
</table>
<script type="text/javascript">
function saveTextAsFile(textToWrite, fileNameToSaveAs)
{
var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'});
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
if (window.webkitURL != null)
{
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
}
downloadLink.click();
}
</script>
</body>
</html>