Page 1 of 1

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

Posted: Tue Jul 19, 2022 7:51 pm
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.

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

Posted: Tue Jul 19, 2022 7:58 pm
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;

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

Posted: Thu Jul 21, 2022 7:48 am
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.