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.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

interceptar alert de codigo js

Post Reply
sistemas
Posts: 3
Joined: Fri May 20, 2022 4:38 pm

interceptar alert de codigo js

Post by sistemas »

olá, preciso pegar o retorno deste codigo em js no webview4delphi ---
var rows = document.getElementsByTagName
("table")[1].rows;
var totalRowCount = rows.length;
alert(totalRowCount-3);
for (var j = 0; j < (totalRowCount-3); j++) {
// numero de rows - linhas
for (var i = 0; i < (15); i++) { // numero
de campos - colunas
var last = rows[j];
var cell = last.cells;
var value = 'J' +String( j).padStart(2, '0') + 'I' +
String(i).padStart(2, '0') + ' - ' + cell.innerHTML
alert(value)
}
}

este codigo funciona no delphi interceptando o alert...
como eu faria isto no webview4delphi .
grato!
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: interceptar alert de codigo js

Post by salvadordf »

Hi,

Set TWVBrowserBase.DefaultScriptDialogsEnabled to false and use the TWVBrowserBase.OnScriptDialogOpening event to suppresses or replace JS dialogs with custom dialogs.

If you are using this to send information to Delphi/Lazarus then consider using the code in the BrowserHostAppCommunication demo.
sistemas
Posts: 3
Joined: Fri May 20, 2022 4:38 pm

Re: interceptar alert de codigo js

Post by sistemas »

tentei capturar o retorno do script
através de
procedure TMainForm.WVBrowser1ScriptDialogOpening(Sender: TObject;
const aWebView: ICoreWebView2;
const aArgs: TCoreWebView2ScriptDialogOpeningEventArgs);

ele dá o alert na tela mas não passa pela procedure acima no debug.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: interceptar alert de codigo js

Post by salvadordf »

It's necessary to set TWVBrowserBase.DefaultScriptDialogsEnabled to False when the browser is already initialized.

Use the TWVBrowserBase.OnAfterCreated event to set TWVBrowserBase.DefaultScriptDialogsEnabled to False.

After that, you will start getting the TWVBrowserBase.OnScriptDialogOpening events.
sistemas
Posts: 3
Joined: Fri May 20, 2022 4:38 pm

Re: interceptar alert de codigo js

Post by sistemas »

valeu, deu certo, obrigado!
Post Reply