TAdvWebBrowser detect data change or URL-redirect(ed)?

Hi,
Since we are exploring the possibilities of the TAdvWebBrowser, we are wondering if it is somehow possible to detect changes in data/redirects and then fire an event?
Basically we load a webpage in de browser and are being redirected after pressing a "login" button.
So far we were only able to manually fire the AdvWebBrowser1.ExecuteJavaScript function but we would like to fire it when data on the webpage is changed or a redirect is being done by the server.

Can you try using the OnNavigateComplete event?

Hi @Pieter_Scheldeman this event is only triggered once. When we are being redirected after pressing the button on the webpage, the event is not triggered.

Here is a complete sample

unit Unit6;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, AdvCustomControl, AdvWebBrowser;

type
  TForm6 = class(TForm)
    AdvWebBrowser1: TAdvWebBrowser;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form6: TForm6;

implementation

{$R *.dfm}

uses
  AdvUtils, AdvWebBrowser.Win;

type
  TCoreWebView2HistoryChangedEventHandler = class(TInterfacedPersistent, ICoreWebView2HistoryChangedEventHandler)
    function Invoke(sender: ICoreWebView2; args: IUnknown): HRESULT; stdcall;
  end;

procedure TForm6.FormCreate(Sender: TObject);
var
  w: ICoreWebView2;
  c: ICoreWebView2Controller;
  e: EventRegistrationToken;
begin
  c := ICoreWebView2Controller(AdvWebBrowser1.NativeBrowser);
  if c.get_CoreWebView2(w) = S_OK then
    w.add_HistoryChanged(TCoreWebView2HistoryChangedEventHandler.Create, @e);

  AdvWebBrowser1.URL := 'https://maps.google.com';
end;

{ TCoreWebView2HistoryChangedEventHandler }

function TCoreWebView2HistoryChangedEventHandler.Invoke(sender: ICoreWebView2;
  args: IInterface): HRESULT;
var
  s: string;
begin
  Result := S_OK;
  if sender.get_Source(@s) = S_OK then
  begin
    TAdvUtils.Log(s);
  end;
end;

end.

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.