Page 1 of 1

Browser.MainFrame.GetV8Context return nil

Posted: Wed Jul 15, 2020 12:28 am
by yesilcimenahmet
Link: viewtopic.php?t=373&fbclid=IwAR0eqsEndP ... JmATolL0ac

I read this post. Because I have same problem. I try to get v8context from mainframe it returns nil and said that the person on the forum had the same problem.

Because I need to call;

Code: Select all

V8Context.Enter

..Create some object

V8Context.Exit;
But it is impossible, because MainFrame.GetV8Context returns nil!ΓΌ

According to the answer given in stackoverflow, they took the v8context value in the mainframe and worked it in C++.

I had the same problem on C++! And I have solved it with following code:

CefRefPtr<CefFrame> frame = browser->GetMainFrame();
CefRefPtr<CefV8Context> v8Context = frame->GetV8Context();
if (v8Context.get() && v8Context->Enter())
{
CefRefPtr<CefV8Value> object = CefV8Value::CreateObject(NULL);
// ExecuteFunctionWithContext and other actions

v8Context->Exit();
}
https://stackoverflow.com/questions/988 ... utefunctio

Please Help.

Re: Browser.MainFrame.GetV8Context return nil

Posted: Wed Jul 15, 2020 8:21 am
by salvadordf
This is a working example to get the v8context :
https://github.com/salvadordf/CEF4Delph ... l.pas#L503

If you can't use that example then try calling this to get the current (top) context object in the V8 context stack.

Code: Select all

MyV8Context := TCefv8ContextRef.Current;