Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8253696

WebEngine refuses to load local "file:///" CSS stylesheets when using JDK 15

    XMLWordPrintable

    Details

    • Subcomponent:
      web
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Any OS. OpenJDK 15 with JavaFX 15.

      A DESCRIPTION OF THE PROBLEM :
      WebView can load local, "file:///", HTML page but when such page is styled by a local, "file:///", CSS stylesheet, this CSS stylesheet is not loaded. The error message is:

      Did not parse stylesheet at 'file:///home/.../red.css' because non CSS MIME types are not allowed in strict mode.[file:///home/.../page.html:0]

      There is no such problem with HTML pages/CSS stylesheets having a "http://" or "https://" URL (because the web server returns a valid MIME type for all the files it serves ???).

      This is a regression. It used to work fine with any previous version of JavaFX, including 14.0.2.


      REGRESSION : Last worked in version 14.0.2

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Compile attached SimpleBrowser.java:
      javac SimpleBrowser.java

      2) Save this HTML snippet to file "page.html":
      ---
      <!DOCTYPE html>
      <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
          <meta charset="UTF-8" />
          <title>A page</title>
          <link rel="stylesheet" href="red.css" type="text/css" />
        </head>
        <body>
          <p>If CSS stylesheet "<code>./red.css</code>" is successfully loaded,
          this paragraph should contain some <strong>RED</strong> text.</p>
        </body>
      </html>
      ---

      3) Save this CSS snippet to file "red.css":
      ---
      p {
          color: red;
      }
      ---

      4) Run using OpenJDK 15+ JavaFX 15 on any OS:
      java SimpleBrowser page.html

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      "page.html" displayed by SimpleBrowser contains some red text and no error is reported.
      ACTUAL -
      "page.html" displayed by SimpleBrowser contains some black text.

      This error is reported:
      Did not parse stylesheet at 'file:///home/.../red.css&#39; because non CSS MIME types are not allowed in strict mode.[file:///home/.../page.html:0]


      ---------- BEGIN SOURCE ----------
      import java.io.File;
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.layout.VBox;
      import javafx.scene.web.WebView;
      import javafx.stage.Stage;

      public class SimpleBrowser extends Application {
          public static void main(String[] args) {
              if (args.length != 1) {
                  System.err.println("Usage: java SimpleBrowser HTML_file_or_URL");
                  System.exit(1);
              }
                  
              launch(args);
          }

          public void start(Stage primaryStage) {
              primaryStage.setTitle("JavaFX SimpleBrowser");

              WebView webView = new WebView();

              com.sun.javafx.webkit.WebConsoleListener.setDefaultListener(
                  (aWebView, message, lineNumber, sourceId) ->
                  System.err.println("WebConsoleListener: " + message +
                                     "[" + aWebView.getEngine().getLocation() +
                                     ":" + lineNumber + "]"));

              String location = getParameters().getRaw().get(0);
              if (location.indexOf(":/") < 0) {
                  File file = new File(location);
                  if (file.isFile()) {
                      location = file.toURI().toASCIIString();
                  }
              }
              
              webView.getEngine().load(location);

              VBox vBox = new VBox(webView);
              Scene scene = new Scene(vBox, 960, 600);

              primaryStage.setScene(scene);
              primaryStage.show();
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      No workaround.

      FREQUENCY : always


        Attachments

        1. page.html
          0.4 kB
        2. red.css
          0.0 kB
        3. SimpleBrowser.java
          1 kB

          Issue Links

            Activity

              People

              Assignee:
              ajoseph Arun Joseph (Inactive)
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: