How do I get the result from executing JavaScript in an embedded Chromium control?
Asked Answered
R

2

6

How can I execute JavaScript and get its result in DCEF3? I would appreciate if someone could write a simple example of how this can be done.

I can execute JavaScript with the code below, but it doesn't provide the result.

Browser.MainFrame.ExecuteJavaScript('app.doit(''foo'')', '', 0);
Recall answered 13/9, 2013 at 18:48 Comment(0)
J
2

Here is my workaroud : use 'console.log()' JS command. The idea is to run the desired JS code and log the result to the console ; after this, you can intercept the console message and get the result.

Example :

var a = 1; 
var b = 2;
var result = a + b;
console.log(result);
return result;

It's not the ideal but worked for me.

Joyann answered 12/6, 2016 at 22:24 Comment(0)
M
1

From python implementation wiki:

This function executes asynchronously so there is no way to get the returned value. Calling javascript from native code synchronously is not possible in CEF 3. It is also not possible doing it synchronously the other way around ie. js->native.

Mirabel answered 15/11, 2013 at 18:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.