Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

350
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda