For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt, and this page is available as Markdown at /next/api/lynx-native-api/lynx-extension-module/on-runtime-ready.md.
Lynx
  • English
  • OnRuntimeReady

    OnRuntimeReady is a virtual lifecycle method in the LynxExtensionModule class. It is called after the BTS runtime is attached and the initial JavaScript environment has been fully set up.

    This callback is always invoked on the BTS thread. It signifies that the runtime is now fully operational and ready to execute JavaScript code. This is the point where you can safely interact with the global lynx object and perform tasks that depend on the page's initial state.

    Method Signature

    virtual void OnRuntimeReady(Napi::Env env, Napi::Value lynx, const char* url);

    Parameters

    NameTypeDescriptionRequired
    envNapi::EnvThe N-API environment handle, same as the one provided in OnRuntimeAttach.Yes
    lynxNapi::ValueA N-API handle to the global lynx object in the JavaScript context. This object provides access to various Lynx-specific APIs and properties.Yes
    urlconst char*The URL of the current Lynx page being loaded.Yes

    Usage

    Override this method to perform actions that need to happen once the JavaScript environment is live. Common use cases include:

    • Executing initial JavaScript code.
    • Getting or setting properties on the global lynx object.
    • Triggering initial data fetches or other asynchronous operations from native code.

    Example

    #include "lynx_extension_module.h"
    
    class MyExtensionModule : public lynx::pub::LynxExtensionModule {
    public:
        void OnRuntimeReady(Napi::Env env, Napi::Value lynx, const char* url) override {
            printf("MyExtensionModule: Runtime is ready for URL: %s\\n", url);
    
            // Example: Get a property from the global 'lynx' object
            if (lynx.IsObject()) {
                Napi::Object lynx_obj = lynx.As<Napi::Object>();
    
                // Get 'platform' property
                if (lynx_obj.Has("platform")) {
                    Napi::Value platform_value = lynx_obj.Get("platform");
    
                    // Convert to string and print
                    if (platform_value.IsString()) {
                        std::string platform_str = platform_value.As<Napi::String>().Utf8Value();
                        printf("Detected Lynx platform: %s\\n", platform_str.c_str());
                    }
                }
            }
        }
    
        // ... other lifecycle methods
    };

    See Also

    Compatibility

    LCD tables only load in the browser

    Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.