Getting the JS Context for a View
Most calls in JavaScriptCore requires an execution context. You can get the global JS context for the current page via View::js_context().
// Use LoadListener::OnDOMReady to wait for page scripts to load
void MyApp::OnDOMReady(View* view) {
// Get the JS execution context for the current page
JSContextRef ctx = view->js_context();
// Use the context in JavaScriptCore API calls here...
}JS Context Lifetime
Just note that this context may change between page loads-- when the context changes all garbage-collected objects (JSValueRef and JSObjectRef) are no longer valid.
Updated 6 months ago
What’s Next
