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.

Communication between Javascript and CEF

Post Reply
ChristianH
Posts: 1
Joined: Sun Apr 18, 2021 10:57 am

Communication between Javascript and CEF

Post 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?
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Communication between Javascript and CEF

Post 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.
Post Reply