Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

Calling a web page via a button and from the procedure "wbBrowser_NavigationCompleted" behaves differently.

Post Reply
polass
Posts: 13
Joined: Sun Jun 12, 2022 6:59 pm

Calling a web page via a button and from the procedure "wbBrowser_NavigationCompleted" behaves differently.

Post by polass »

I apologize in advance for not being able to publish the source code, I will try to explain the problem in general:
- I call a specific website with login (user, password) via the button

Code: Select all

procedure TfrmBrowser.btn1Click(Sender: TObject);
begin
  wbBrowser.Navigate(any_www);
end;
- I wait for the page to load and use 3 ExecuteScript to fill in the user, password and press the "confirm" button

Code: Select all

procedure TfrmBrowser.wbBrowser_NavigationCompleted (Sender: TObject; const aWebView: ICoreWebView2; const aArgs: ICoreWebView2NavigationCompletedEventArgs);
begin
    wbBrowser.ExecuteScript('document.getElementById("*txtLogin*").value = "login"',0);
    wbBrowser.ExecuteScript('document.getElementById("*txtPassword*").value = "psw"',0);
    wbBrowser.ExecuteScript('document.getElementById("*ID_button*").click();', 1 );
    ...
    ...
end;
- I wait for the login and call the next_web_page in the wbBrowser_NavigationCompleted procedure. But this call does not retrieve the FResourceContents in the procedure wbBrowser_WebResource_ResponseViewGetContent_Completed - the constant aContents = nil
- However, calling the same page via a button

Code: Select all

procedure TfrmBrowser.btn1Click(Sender: TObject);
begin
  wbBrowser.Navigate(next_web_page);
end;
will return the constant aContens correctly and return a filled FResourceContents.
Can you please advise what I am doing wrong? I hope I have described it clearly.
polass
Posts: 13
Joined: Sun Jun 12, 2022 6:59 pm

Re: Calling a web page via a button and from the procedure "wbBrowser_NavigationCompleted" behaves differently.

Post by polass »

Addition - simplification of the query:
call wbBrowser.Navigate(any_www)
via button_onclick - aContens = ok

Code: Select all

procedure TfrmBrowser.btn1Click(Sender: TObject);
begin
  wbBrowser.Navigate(any_www);
end;
via wbBrowser_NavigationCompleted - aContens = nil

Code: Select all

procedure TfrmBrowser.wbBrowser_NavigationCompleted (Sender: TObject; const aWebView: ICoreWebView2; const aArgs: ICoreWebView2NavigationCompletedEventArgs);
begin
  wbBrowser.Navigate(any_www);
end;
User avatar
salvadordf
Posts: 4089
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Calling a web page via a button and from the procedure "wbBrowser_NavigationCompleted" behaves differently.

Post by salvadordf »

This might be a WebView2 issue.

Try sending a custom windows message from wbBrowser_NavigationCompleted to the main form and navigate to the next page in the procedure that handles that custom message.
Post Reply