JDK-8175170 : WebView fails to render after application stays inactive for a while
  • Type: Bug
  • Component: javafx
  • Sub-Component: web
  • Affected Version: 8u102
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2017-02-16
  • Updated: 2017-03-09
  • Resolved: 2017-02-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8u152Resolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
The issue is with WebView component. Sometimes if the application stays idle for a few minutes, the display is just a blank screen and WebView is not rendered on the stage. Other times it works perfectly fine. Also once a particular WebView component fails to render onto  the screen, all other WebViews throughout the application fail to load.

The component behaves very inconsistently and I couldn't identify a definitive pattern to replicate the issue.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Open a page with WebView component in it.
2. Go to a different page with no WebView components.
3. Leave the application idle for about 10 minutes.
4. Load the page with WebView component. The page loads but the WebView component is not rendered.

---------------------------------
My WebView code:
---------------------------------
String htmlBillText = billTextController.transformBillXmlXsl();

WebView webView = new WebView();
WebEngine engine = webView.getEngine();
engine.setOnError((WebErrorEvent event) -> {
    // NEVER GOES INTO THIS AT ALL
    System.out.println("event.getMessage()::"+event.getMessage());
    System.out.println("event.getException()::"+event.getException().getMessage());
    System.out.println("event.toString()::"+event.toString());
    engine.reload();
});

engine.getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>() {
    @Override
    public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) {

        System.out.println("oldState::" + oldState);
        System.out.println("newState::" + newState);
        if (engine.getLoadWorker().getException() != null) {
            System.out.println("engine.getLoadWorker().getException()::" + engine.getLoadWorker().getException().getLocalizedMessage());
        }

        if (engine.getLoadWorker().getException() != null && newState == Worker.State.FAILED) {
            System.out.println(engine.getLoadWorker().getException().getMessage());
        }

        if (newState == Worker.State.SUCCEEDED) {
            System.out.println("engine.getDocument()::"+engine.getDocument());
            if (engine.getDocument() != null) {
                String html = (String) engine.executeScript("document.documentElement.innerHTML");
                if (StringUtils.isEmpty(html)) {
                    System.out.println("FX WebView Engine Failed To Load Content... Execute Reload...");
                    engine.reload();
                }
            }
            System.out.println("engine.getTitle()::" + engine.getTitle());
            System.out.println("engine.getLocation()::" + engine.getLocation());
            System.out.println("engine.getUserAgent()::" + engine.getUserAgent());
            System.out.println("engine.getUserDataDirectory()::" + engine.getUserDataDirectory());
            System.out.println("engine.isJavaScriptEnabled()::" + engine.isJavaScriptEnabled());
        }
    }
});
engine.loadContent(htmlBillText);

-----------------------------------------------------------------------------------
MY DISPLAY CONSOLE WHEN WEBVIEW FAILS TO LOAD:
-----------------------------------------------------------------------------------
oldState::READY
newState::SCHEDULED
oldState::SCHEDULED
newState::RUNNING
oldState::RUNNING
newState::SUCCEEDED
engine.getDocument()::[object HTMLDocument]
engine.getTitle()::SB6:v98#DOCUMENT
engine.getLocation()::
engine.getUserAgent()::Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/538.19 (KHTML, like Gecko) JavaFX/8.0 Safari/538.19
engine.getUserDataDirectory()::null
engine.isJavaScriptEnabled()::true

---------------------------------------------------------------------------------

Thanks. -Sirish Vadala

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The WebView should always load and render the content even if the application stays idle for a certain period of time, at least for 15-20 minutes.
ACTUAL -
The page loads but the WebView component within the page is not rendered. The engine loads the content as per the output console, but the WebView fails to render on to the screen. This happens so inconsistently, with no definitive pattern, but usually keeping the application idle for a while makes it happen.

Output console when application fails:
---------------------------------------------------
oldState::READY
newState::SCHEDULED
oldState::SCHEDULED
newState::RUNNING
oldState::RUNNING
newState::SUCCEEDED
engine.getDocument()::[object HTMLDocument]
engine.getTitle()::SB6:v98#DOCUMENT
engine.getLocation()::
engine.getUserAgent()::Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/538.19 (KHTML, like Gecko) JavaFX/8.0 Safari/538.19
engine.getUserDataDirectory()::null
engine.isJavaScriptEnabled()::true

REPRODUCIBILITY :
This bug can be reproduced often.


Comments
Closing as a duplicate of JDK-8166999 (the latest WebKit upgrade).
20-02-2017

Verified in JDK 8u152 - PASS.
20-02-2017

JDK 9 has an updated WebKit which is also in the recently-posted JDK 8u152-ea build. We should test it there as well to see if it is already fixed for 8u, too.
17-02-2017

Steps to reproduce: ************************** - Run the attached file(WebViewDemo.java) with JDK. - Leave the application idle for about 10 minutes. - Webview page is not responding
17-02-2017

Verified this issue against JDK 8,9, It is an regression in 8 introduced in 8u102. Below are the results. JDK: +++++++++++++++++++++++++ 8u101 - PASS 8u102 - FAIL 8u121 - FAIL 9ea156 - PASS ===========================
17-02-2017