Creating and sending CustomEvent objects from a v8 context.

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.

Creating and sending CustomEvent objects from a v8 context.

Postby DDRBoxman » Tue Sep 13, 2016 8:49 am

I have an OnProcessMessageReceived callback in my render process handler where I would like to create a CustomEvent object and dispatch it on the window object.

https://developer.mozilla.org/en-US/doc ... ustomEvent

This was my inital attempt but the CustomEvent object is never recognised as an Event object by the browser.

Code: Select all
CefRefPtr<CefV8Value> globalObj = context->GetGlobal();

CefRefPtr<CefV8Value> customEvent = globalObj->GetValue("CustomEvent");
CefRefPtr<CefV8Value> prototype = customEvent->GetValue("prototype");

CefV8ValueList prototypeArgs;
prototypeArgs.push_back(prototype);
prototypeArgs.push_back();

CefRefPtr<CefV8Value> object = globalObj->GetValue("Object");
CefRefPtr<CefV8Value> create = object->GetValue("create");
CefRefPtr<CefV8Value> event = create->ExecuteFunction(NULL, prototypeArgs);
event->SetValue("type", CefV8Value::CreateString(args->GetString(0)), V8_PROPERTY_ATTRIBUTE_NONE);

globalObj->SetValue("taco", event, V8_PROPERTY_ATTRIBUTE_NONE);

CefV8ValueList arguments;
arguments.push_back(event);

CefRefPtr<CefV8Value> dispatchEvent = globalObj->GetValue("dispatchEvent");
dispatchEvent->ExecuteFunction(NULL, arguments);



Actually after trying similar code the browser will only let me create a new one with the new operator. Is there a way to do that from my v8 context?
DDRBoxman
Newbie
 
Posts: 2
Joined: Tue Sep 13, 2016 8:43 am

Re: Creating and sending CustomEvent objects from a v8 conte

Postby magreenblatt » Tue Sep 13, 2016 11:55 am

You can try CefFrame::ExecuteJavaScript of CefV8Context::Eval instead.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: Creating and sending CustomEvent objects from a v8 conte

Postby DDRBoxman » Wed Sep 14, 2016 9:56 am

Eval works perfect, thanks!
DDRBoxman
Newbie
 
Posts: 2
Joined: Tue Sep 13, 2016 8:43 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 52 guests

cron