Page 1 of 1

interceptar alert de codigo js

Posted: Sat May 21, 2022 3:04 am
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!

Re: interceptar alert de codigo js

Posted: Sat May 21, 2022 8:03 am
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.

Re: interceptar alert de codigo js

Posted: Sat May 21, 2022 2:14 pm
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.

Re: interceptar alert de codigo js

Posted: Sun May 22, 2022 6:55 pm
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.

Re: interceptar alert de codigo js

Posted: Mon May 23, 2022 6:56 pm
by sistemas
valeu, deu certo, obrigado!