js binding question in c++

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

js binding question in c++

Postby gkellerer » Thu Sep 20, 2018 2:52 am

hello,

i have a little js binding problem and hope that anyone here can help me. i am new to cef and my js knowledge is beginner level. here is my code with comments that show what i like to achieve:
// Render process:
void OnContextCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) OVERRIDE {
message_router_->OnContextCreated(browser, frame, context);
CefRefPtr<CefV8Value> object = context->GetGlobal();
CefRefPtr<CefV8Value> str = CefV8Value::CreateString("default testvalue");
object->SetValue("myevent", str, V8_PROPERTY_ATTRIBUTE_NONE);
// define an eventlistener for window.postmessage that is sent when
// the user on the website enters text andclicks a button
// this works as far as i see correctly. The listener is triggered when the user click the button
/ and the entered text is shown correctly in the alert box
CefString jscode = "window.addEventListener('message'"
", function(event) {"
"window.myevent = event.data.eventType;"
"alert(window.myevent);}, false);";
frame->ExecuteJavaScript(jscode, frame->GetURL(), 0);

CefString val = object->GetValue("myevent")->GetStringValue();
// when i test that value i see that the default value has not changed.
}
}Can anybody tell me what i am doing wrong?

thanks a lot,
Georg
gkellerer
Newbie
 
Posts: 7
Joined: Fri Sep 14, 2018 1:49 am

Re: js binding question in c++

Postby Czarek » Thu Sep 20, 2018 4:53 am

frame->ExecuteJavascript() executes asynchronously. Use context->Eval() to execute code synchronously. If your js code is asynchronous in itself then check the value after it has completed executing.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am


Return to Support Forum

Who is online

Users browsing this forum: Biohazard, Majestic-12 [Bot] and 72 guests

cron