I am just getting started with CEF4Delphi. I have a chromium window on a tab in a page control. There are javascript hooks attached to elements on the webpage which register clicks and fire off native delphi code. This is all working correctly on one webpage. I can switch tabs and keep clicking on the webpage and receiving the click events.
However, when loading a different webpage there is some strange behaviour. The first time the tab is loaded clicks will be registered just fine. The issue arises when switching tabs. The second time a tab is loaded there are no clicks being registered.
This second webpage is being created by blazor which is different to the first but I am not sure why that would be affecting it.
I have tested using Google.com and it works fine on there also.
Chromium1.LoadURL('localhost:6064');
is run when the tab is loaded.
class procedure TmyExtension.ButtonClick(const data: string);
var
msg: ICefProcessMessage;
begin
msg := TCefProcessMessageRef.New('ButtonClick');
TCefv8ContextRef.Current.Browser.MainFrame.SendProcessMessage(PID_BROWSER, msg);
end;
The delphi code being fired
Chromium1.browser.MainFrame.ExecuteJavaScript(
'document.getElementById("'+
'NewButton' +
'").addEventListener("click", function(evt){' +
'function getpath(n){var ret = n.id;' +
'if (n.parentNode){return "" + ret}' +
'else return ret};'
'myextension.ButtonClick(getpath(evt.target))' +
'})', Chromium1.browser.MainFrame.GetURL, 0);
The Javascript being executed
procedure TtabWebPage.Chromium1ProcessMessageReceived(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
sourceProcess: TCefProcessId; const message: ICefProcessMessage;
out Result: Boolean);
begin
if (message = nil) or (message.ArgumentList = nil) then exit;
// This function receives the messages with the JavaScript results
if (message.Name = 'ButtonClick') then begin
Inc(FCount);
Result := True;
end;
inherited;
end;
Receiving the chromium message and increasing a count.
There doesn't seem to be a way to debug whether the javascript is being run. The ExecuteJavaScript function is definitely being run every time the page loads. I am wondering if there is anything to do with the blazor aspect of the webpage that causes this, or if there is any way to debug the issue.