Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

348
Views
CEF - how to get a variable from JS to С++

Please help me, I've been suffering for two weeks, I can't understand if it's possible in CEF to get the value of a variable from the JS code to a C++ variable?

For example:

I am executing js code in a browser window using the method CefFrame::ExecuteJavaScript:

(*frame).GetMainFrame()).ExecuteJavaScript("const elem = document.getElementsByClassName("my_class")[0];const rect = elem.getBoundingClientRect(); alert(rect.x + \":\" + rect.y)", "", 1);

And everything works great, but only "inside" javascript.

Here's the question: is it possible to somehow get the value of a variable to a rect.x to pull out and put in a C++ variable int rect_x ?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

You might have noticed, if you type rect.x in the console in the developer tools, it echoes the variable value. It should have hinted you, how to retrieve variable values.

CefRefPtr<CefV8Context> v8_context = frame->GetMainFrame()->GetV8Context();
if (v8_context.get() && v8_context->Enter()) {
  CefRefPtr<CefV8Value> retval;
  CefRefPtr<CefV8Exception> exception;
  if (v8_context->Eval("rect.x", "", 0, retval, exception)) {
    int rect_x = retval->GetIntValue()
  }
  v8_context->Exit();
}
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!