JxBrowser provides functionality that you can use to detect when the loaded web page becomes unresponsive (e.g. because JavaScript execution on the web page take more than 30 seconds). When the web page becomes unresponsive you can display alert message to the end user to inform them about the situation and suggest to wait or kill the Browser instance. Also, you can get notifications when web page becomes responsive again.(JxBrowser提供的功能可用于检测加载的网页何时无响应(例如,因为该网页上的JavaScript执行需要30秒钟以上)。当网页无响应时,您可以向最终用户显示警报消息,以告知他们有关情况,并建议等待或终止浏览器实例。另外,当网页再次响应时,您可以获得通知。)


The following example code demonstrates how to register RenderListener for getting these notifications:(以下示例代码演示了如何注册RenderListener以获得这些通知:)

Browser browser = new Browser();
browser.addRenderListener(new RenderAdapter() {
    @Override
    public void onRenderUnresponsive(RenderEvent event) {
        // Web page is unresponsive :(
    }

    @Override
    public void onRenderResponsive(RenderEvent event) {
        // Web page is responsive again :)
    }
});

To kill the Browser instance when web page becomes unresponsive you can use the Browser.dispose() method.(要在网页无响应时杀死Browser实例,可以使用Browser.dispose()方法。)


Note: Chromium doesn't fire the onRenderUnresponsive event if there was no user activity (mouse or keyboard events) on the unresponsive web page. There's an internal timer in Chromium functionality that watches user activity and decide whether the onRenderUnresponsive event should be fired or not depending on the unresponsive state since last mouse or keyboard event sent to the web page. If you freeze the web page, but no mouse or keyboard events are sent to the web page since that freeze, Chromium will not send the onRenderUnresponsive event.(注意:如果无响应的网页上没有用户活动(鼠标或键盘事件),Chromium不会触发onRenderUn响应事件。 Chromium功能中有一个内部计时器,用于监视用户活动并根据自上次鼠标或键盘事件发送至网页以来的无响应状态,决定是否应触发onRenderUn响应事件。如果您冻结了该网页,但自冻结以来没有任何鼠标或键盘事件发送到该网页,则Chromium将不会发送onRenderUn响应事件。)