1

Topic: CEF and a call js functions from a C ++

Greetings to everything,  a subject, but distinct examples how to cause already existing in the loaded page to transfer parameters and to receive result. Everywhere any examples with ExecuteJavascript, but it is explicit not that. Somebody faced?

2

Re: CEF and a call js functions from a C ++

RW>  a subject, but distinct examples how to cause already existing in the loaded page to transfer parameters and to receive result. Everywhere any examples with ExecuteJavascript, but it is explicit not that. Somebody faced? Conditionally, the page should open in any browser or in your application? If the second through IWebBrowser2 we such did a component.

3

Re: CEF and a call js functions from a C ++

Hello, Temnikov, you wrote: RW>>  a subject, but distinct examples how to cause already existing in the loaded page to transfer parameters and to receive result. Everywhere any examples with ExecuteJavascript, but it is explicit not that. Somebody faced? T> it is conditional, the page should open in any browser or in your application? If the second through IWebBrowser2 we such did a component. Interests only CEF, for IWebBrowser2 for a long time somehow did - to , refused from IE.

4

Re: CEF and a call js functions from a C ++

On  SignalR from the ready. Or it is possible to make simply on web sockets an exchange, and there already the flight of fancy is restricted by nothing.

5

Re: CEF and a call js functions from a C ++

Hello, Temnikov, you wrote: T> On  SignalR from the ready. Or it is possible to make simply on web sockets an exchange, and there already the flight of fancy is restricted by nothing. What, I apologize,  a web sockets? I need to cause from a C ++ existing functions js, it perfectly does ExecuteJavascript, but to receive result not clearly as well as to format a line with arguments for a call js functions I do not want

6

Re: CEF and a call js functions from a C ++

RW> what, I apologize,  a web sockets? I need to cause from a C ++ existing functions js, it perfectly does ExecuteJavascript, but to receive result not clearly as well as to format a line with arguments for a call js functions does not want RW>> how to cause Rasparsil already existing in loaded page as that you have a page and you should cause a C ++ function from any library.

7

Re: CEF and a call js functions from a C ++

Hello, Temnikov, you wrote: RW>> what, I apologize,  a web sockets? I need to cause from a C ++ existing functions js, it perfectly does ExecuteJavascript, but to receive result not clearly as well as to format a line with arguments for a call js functions I do not want T> Rasparsil as that you have a page and you should cause a C ++ function from any library. Yes like so wrote

8

Re: CEF and a call js functions from a C ++

Hello, RonWilson, you wrote: RW> Greetings to everything, RW>  a subject, but distinct examples how to cause already existing in the loaded page to transfer parameters and to receive result. Everywhere any examples with ExecuteJavascript, but it is explicit not that. Somebody faced? https://bitbucket.org/chromiumembedded/ … gration.md look at source codes to articles CEF, ES6, Angular 2, TypeScript usage of classes.Net Core. Creation  GUI for.Net by means of CEF CEF, Angular 2 usage of events of classes.Net Core asynchronous calls and a subscription to events There are used. Look SetCallBacks ("RegisterCallBacks"), AsyncCalBack That is you should register function window. RegisterCallBacks (AsyncCallBack, EventCall); And then it to cause for example function EventCall (EventKey, result) {alert ("EventKey =" + EventKey + "result =" + result);} window. RegisterCallBacks (AsyncCallBack, EventCall); RegisterCallBacks it is yours  function in CEF. You transfer links to methods. In CEF you remember, and then you cause out of need

9

Re: CEF and a call js functions from a C ++

Hello, RonWilson, you wrote: RW> and to receive result ExecuteFunctionWithContext?

10

Re: CEF and a call js functions from a C ++

Hello, RonWilson, you wrote: RW> what, I apologize,  a web sockets? I need to cause from a C ++ existing functions js, it perfectly does ExecuteJavascript, but to receive result not clearly as well as to format a line with arguments for a call js functions I do not want Your code and a script are executed, generally speaking, in different processes. If it is necessary to solve faster, you can try to place parameters in global object (window. MyObject) to cause - which places returned value approximately there. A little clumsily, certainly. I did not try.

11

Re: CEF and a call js functions from a C ++

Hello, goto, you wrote: G> Your code and a script are executed, generally speaking, in different processes. If it is necessary to solve faster, you can try to place parameters in global object (window. MyObject) to cause - which places returned value approximately there. A little clumsily, certainly. I did not try. So works: void CefViewApp:: OnContextCreated (CefRefPtr <CefBrowser> browser, CefRefPtr <CefFrame> frame, CefRefPtr <CefV8Context> context) {CefRefPtr <CefV8Value> object = context-> GetGlobal (); CefRefPtr <CefV8Value> str = CefV8Value:: CreateString ("HehHHH"); object-> SetValue ("testVal", str, V8_PROPERTY_ATTRIBUTE_NONE);} function test () {alert (window.testVal);} CefRefPtr <CefFrame> frame = cefHandler-> GetBrowser ()-> GetMainFrame (); if (! frame.get ()) return (LRESULT) FALSE; frame-> ExecuteJavaScript (CefString ("test ();" ), frame-> GetURL (), 0); but, how much I understood, ExecuteJavaScript too asynchronous how then to receive result right after ExecuteJavaScript? In CefFrame call GetV8Context returns a zero, it and is clear - well only at , and it is necessary for me during the arbitrary moment P.S. And why such perversion with access to DOM how addresses to DOMDocument too from the arbitrary place?

12

Re: CEF and a call js functions from a C ++

Hello, RonWilson, you wrote: Try to use ExecuteFunctionWithContext CefV8ValueList args; CefRefPtr <CefV8Value> retval; CefRefPtr <CefV8Exception> exception; if (callback_func_->ExecuteFunctionWithContext (callback_context _, NULL, args, retval, exception, false)) {if (exception.get() {//Execution threw an exception.} else {//Execution succeeded.}} retval also there is your function. You can register universal function which will to accept a method title, parameters, and inside to cause eval and to return result

13

Re: CEF and a call js functions from a C ++

Hello, Serginio1, you wrote: S> you Can register universal function which will to accept a method title, parameters, and inside to cause eval and to return result unfortunately - there was only a question with where it is better to store received funct and ctx that it was possible to use in the fullness of time. Whether it is possible in implementation of the CefApp as class fields?: bool GeneralCefV8Handler:: Execute (const CefString& name, CefRefPtr <CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception) {if (name == NATIVECALLBACKREGISTER) {if (arguments.size () == 1 && arguments [0]-> IsFunction ()) {CefRefPtr <CefV8Value> funct = arguments [0]; CefRefPtr <CefV8Context> ctx = CefV8Context:: GetCurrentContext ();//test CefV8ValueList args; CefRefPtr <CefV8Value> retval = funct-> ExecuteFunctionWithContext (ctx, 0, args); return true;}}//Function does not exist. return false;}

14

Re: CEF and a call js functions from a C ++

Understood, that is necessary for me, namely - the synchronous call js becomes so - suddenly to whom it is useful: here there is a call js functions function SetContent (content) {... return true;},  in CefV8Handler:: Execute void SignalEvent (CefRefPtr <CefWaitableEvent> event) {event-> Signal ();} void RunOnThread (CefThreadId cefTID, const base:: Callback <void (void) >& functImpl, CefRefPtr <CefWaitableEvent> event) {if (! CefCurrentlyOn (cefTID)) {CefPostTask (cefTID, base:: Bind (RunOnThread, cefTID, functImpl, event)); return;} functImpl. Run (); SignalEvent (event);} static void OnLoadHTMLData_Worker (const char * content, bool * retVal) {REQUIRE_RENDERER_THREAD (); if (! content ||! retVal) return; *retVal = false; CefRefPtr <CefV8Value> setContent = g_cefApp-> Get_js_SetContent (); CefRefPtr <CefV8Context> setContent_Ctx = g_cefApp-> Get_js_SetContent_Ctx (); CefV8ValueList args; args.push_back (CefV8Value:: CreateString (content)); CefRefPtr <CefV8Value> retval = setContent-> ExecuteFunctionWithContext (setContent_Ctx, 0, args); if (retval.get () && retval-> IsBool ()) *retVal = retval-> GetBoolValue ();} LRESULT CefViewJSEditorCtrl:: OnLoadHTMLData (HWND hWindow, UINT/*message*/, WPARAM/*wParam*/, LPARAM lParam) {if (! lParam ||! cefHandler.get () ||! cefHandler-> GetBrowser ().get ()) return (LRESULT) FALSE; CefRefPtr <CefFrame> frame = cefHandler-> GetBrowser ()-> GetMainFrame (); if (! frame.get ()) return (LRESULT) FALSE; bool retVal = false; CefRefPtr <CefWaitableEvent> event = CefWaitableEvent:: CreateWaitableEvent (true, false); RunOnThread (TID_RENDERER, base:: Bind (OnLoadHTMLData_Worker, (const char *) lParam, &retVal), event); event-> Wait (); return retVal? (LRESULT) TRUE: (LRESULT) FALSE;}

15

Re: CEF and a call js functions from a C ++

Hello, RonWilson, you wrote: RW> but how much I understood, ExecuteJavaScript too asynchronous how then to receive result right after ExecuteJavaScript? In CefFrame call GetV8Context returns a zero, it and is clear - well only at , and it is necessary for me during the arbitrary moment Yes, the thought about asynchrony at me just flickered the day before. It is possible to give result js f-ii, causing from it  . It too is similar to a perversion for the majority of situations. It is better to look, of course, ExecuteFunctionWithContext as advised c-smile and Serginio1. I once had a small prompt project with usage CEF. I remember, simplified a situation switching in a mode single_process and sandbox switch-off. But a detail, alas, I do not remember, there there was a permanent time trouble and madness.