Page 1 of 1

Communication between Javascript and CEF

Posted: Sun Apr 18, 2021 11:00 am
by ChristianH
Hi,

i have a problem communicating between javascript and CEF. What I do is the following:

Code: Select all

  window.signalCef = function(command) {
           window._HBBTV_DEBUG_ && console.log("signalCef(" + command + ")");
		  
		   var iframe = document.createElement("iframe");
				    iframe.setAttribute("src", "jsevent://" + command);
                    document.documentElement.appendChild(iframe);
                    iframe.parentNode.removeChild(iframe);
                    iframe = null;
		   

	};
In Delphi i do

Code: Select all

procedure TfrmMain.DoChromiumOnBeforeResourceLoad(Sender: TObject;
  const browser: ICefBrowser; const frame: ICefFrame;
  const request: ICefRequest; const callback: ICefRequestCallback;
  out Result: TCefReturnValue);
var
  url: string;
begin
  url := request.getUrl;
  if pos('jsevent://', url) > 0 then
  begin
    EvaluateCommand(Copy(url, pos('://', url) + 3, length(url)));
    Result := RV_CANCEL;
  end;
end;
This partially works. Sometime it just does not receive the request. When I do not RV_CANCEL chrome is raising an exception.

Does someone has a better idea how to interact with the main application from javascript?

Re: Communication between Javascript and CEF

Posted: Mon Apr 19, 2021 8:26 am
by salvadordf
Hi,

CEF 89 had an issue with unregistered URI schemes that caused access violations :
https://github.com/salvadordf/CEF4Delphi/issues/359

Upgrade to the latest CEF4Delphi version which uses CEF 90.