When web page is loaded, Chromium engine creates JavaScript Context instance. This instance represents context in which all JavaScript code is executed. The JavaScript Context instance is created when web page is loaded completely, but JavaScript code on it hasn't been executed yet. To get notifications about JavaScript Context creation use the ScriptContextListener.onScriptContextCreated(ScriptContextEvent event) event.(加载网页后,Chromium引擎将创建JavaScript Context实例。此实例表示在其中执行所有JavaScript代码的上下文。完全加载网页后创建JavaScript Context实例,但是尚未执行该页面上的JavaScript代码。要获取有关JavaScript上下文创建的通知,请使用ScriptContextListener.onScriptContextCreated(ScriptContextEvent event)事件。)

When web page is unloaded because of loading another web page or reloading existing one, Chromium engine destroys JavaScript Context and disposes all JavaScript objects running in scope of this context. To get notifications about JavaScript Context disposal use the ScriptContextListener.onScriptContextDestroyed(ScriptContextEvent event) event.(当由于加载另一个网页或重新加载现有网页而卸载网页时,Chromium引擎会破坏JavaScript上下文,并处置在此上下文范围内运行的所有JavaScript对象。要获取有关JavaScript上下文处理的通知,请使用ScriptContextListener.onScriptContextDestroyed(ScriptContextEvent event)事件。)

You might want to execute some JavaScript code before any other JavaScript on the loaded web page is executed. For example, to inject your own JavaScript objects/functions/properties. JxBrowser API provides functionality that allows receiving notifications before JavaScript code is executed on the loaded web page. To get such notification you must register ScriptContextListener and override its onScriptContextCreated(ScriptContextEvent event) method. Inside this method you can execute your JavaScript code. It will be executed before any other JavaScript on the loaded web page is executed. For example:(在加载的网页上执行任何其他JavaScript之前,您可能需要执行一些JavaScript代码。例如,注入您自己的JavaScript对象/函数/属性。 JxBrowser API提供的功能允许在加载的网页上执行JavaScript代码之前接收通知。要获取此类通知,您必须注册ScriptContextListener并重写其onScriptContextCreated(ScriptContextEvent event)方法。在此方法内,您可以执行JavaScript代码。它会在加载的网页上执行任何其他JavaScript之前执行。例如:)

browser.addScriptContextListener(new ScriptContextAdapter() {
    public void onScriptContextCreated(ScriptContextEvent event) {
        Browser browser = event.getBrowser();
        // Access and modify document.title property before any other
        // JavaScript on the loaded web page has been executed.
        JSValue document = browser.executeJavaScriptAndReturnValue("document");
        document.asObject().setProperty("title", "My title");