---
updatedAt: 2025-06-16T21:15:13.000Z
---

Fetch the complete documentation index at: https://docs.ultralig.ht/llms.txt. Use this file to discover all available pages before exploring further.

# 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::LockJSContext()`](https://ultralig.ht/api/cpp/1_4_0/classultralight_1_1_view.html#a0e53e2acd171f683102242dcc248852d).

```cplusplus
///
/// Use LoadListener::OnDOMReady to wait for the DOM to load.
///
void MyApp::OnDOMReady(View* caller,
                       uint64_t frame_id,
                       bool is_main_frame,
                       const String& url) {
  ///
  /// Acquire the JS execution context for the current page.
  ///
  auto scoped_context = caller->LockJSContext();
  
  ///
  /// Typecast to the underlying JSContextRef.
  ///
  JSContextRef ctx = (*scoped_context);

  /// Make calls to JavaScriptCore API 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.