I’m using the “TEdgeBrowser” component in Delphi12 and I saw on some forums that to be able to “capture” a click in the browser, there was a method using the JS listener and using PostMessage then retrieving it in the component’s “OnWebMessageReceived” event.
sample code
procedure TForm1.EdgeBrowser1WebMessageReceived(Sender: TCustomEdgeBrowser; Args: TWebMessageReceivedEventArgs);
begin
//web retrieval message too slow before the next page is displayed
edgebrowser1.ExecuteScript('document.getElementById("stock").innerText='+inttostr(22));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
edgebrowser1.ExecuteScript(
'function eventClick(e){' +
'e = e || window.event;' +
'var target = e.target || e.srcElement;' +
'var text = target.textContent || target.innerText;'+
'window.chrome.webview.postMessage(target.outerHTML);};');
edgebrowser1.ExecuteScript('window.addEventListener("click",eventClick,{once:true})');
end;
But the problem is that this processing is too slow compared to the display of the previous page.
Basically, the processing to be done on my page is that when a button is clicked, the innerText of the “stock” element on the first page is modified, and when the 2nd page opens it will read the data in this element and display it differently depending on the data retrieved.
But because the postMessage retrieved is too slow, the “stock” element doesn’t have time to be modified. So I wanted to know if there was a way of “capturing” this click?
Jason Fouret is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1