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.

FMX Javascript evaluation

Post Reply
axa
Posts: 13
Joined: Tue May 07, 2019 9:25 pm

FMX Javascript evaluation

Post by axa »

Hi,

How can I evaluate javascript function with FMXChromium and return results.
The sample provided JSEval is available only for VCL applications...
FMX.TWebbrowser from embarcadero ha too many bugs and is unreliable.

I have posted the same question on GitHub, sorry for duplicate

Thank you in advance,
Pavel
User avatar
salvadordf
Posts: 4058
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: FMX Javascript evaluation

Post by salvadordf »

Hi,

You need to mix the SimpleFMXBrowser and JSEval demos into one but please, if you haven't read the following web pages take a few minutes to read them :
https://www.briskbard.com/index.php?lang=en&pageid=cef
https://bitbucket.org/chromiumembedded/ ... gration.md

Read the code comments in the SimpleFMXBrowser and JSEval demos too because adding a TChromium component to an FMX app requires a few steps and the JavaScript demos require inter-process messages and Windows messages.

Use the SimpleFMXBrowser demo as the template for your application and add what you need from the JSEval demo.

You will probably need all this :
  • Use the TChromium.OnBeforeContextMenu and TChromium.OnContextMenuCommand events and copy their code from Chromium1BeforeContextMenu and Chromium1ContextMenuCommand.
  • Copy RenderProcessHandler_OnProcessMessageReceivedEvent and assign it to GlobalCEFApp.OnProcessMessageReceived
  • Copy ParseEvalJsAnswer
  • Use the TChromium.OnProcessMessageReceived to receive the results. Copy Chromium1ProcessMessageReceived.
If your application needs to show or modify anything using the user interface then you will need to send a MINIBROWSER_EVALJSCODE message from TChromium.OnContextMenuCommand but if you already know what you need to evaluate then copy most of the code from EvalJSCodeMsg into TChromium.OnContextMenuCommand to send the EVAL_JS process message.

If you need to show the final results in the user interface then you will need to send a Windows message from the TChromium.OnProcessMessageReceived event. The JSEval demo uses MINIBROWSER_SHOWTEXTVIEWER to show the results in a child form.

As you can see, all the FMX demos use a modified IFMXApplicationService in the uFMXApplicationService.pas file.
Modify the TFMXApplicationService.HandleMessage to add your custom Windows messages.
axa
Posts: 13
Joined: Tue May 07, 2019 9:25 pm

Re: FMX Javascript evaluation

Post by axa »

Dear Salvador,

First of all I want to thank you for your fast reply.
I will try your suggested solution and I will let you know if any problem arise.

Thanks again,
Pavel
Post Reply