All global objects are ‘remote’ (their state is stored in the WebView’s child-process).
Creating Global JS Objects
Creating, manipulating, and accessing these objects is very simple in our C++ API. To create an object, simply call
MyObject from any web page loaded into your WebView.
You can coerce the result into an actual JSObject instance like so:
JSObject& my_object = result.ToObject();
Of course, creating objects alone isn’t very useful–- to give the object some properties, you can use
my_object->SetProperty(WSLit("name"), WSLit("foobar")); my_object->SetProperty(WSLit("color"), WSLit("Blue")); my_object->SetProperty(WSLit("level"), 25);
You can set as many properties as you want, setting a property more than once will replace the previous value. Notice that the last parameter to
SetProperty accepts a JSValue (more on that later).
Order of Initialization
You’ll need to create your Global Object before loading content into your WebView that references the object.
All calls for creating the object and setting its properties should be made before calling
Limitations of Global Objects
Global Objects can only contain the following property types:
- Other Global Objects
Creating a Child of a Global Object