Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

Browser.MainFrame.GetV8Context return nil

Post Reply
yesilcimenahmet
Posts: 10
Joined: Wed Jul 08, 2020 1:25 pm

Browser.MainFrame.GetV8Context return nil

Post 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.
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Browser.MainFrame.GetV8Context return nil

Post 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;
Post Reply