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

localStorage is null after window.close()

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8u141, openjfx11, openjfx14, openjfx15
    • Fix Version/s: tbd
    • Component/s: javafx
    • Subcomponent:
      web
    • CPU:
      generic
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Tested and reproducible on Java 8, 11 and 15 with Linux and Windows 10 with according according JavaFX.

      A DESCRIPTION OF THE PROBLEM :
      When "window.close()" in JavaScript is called within a webpage loaded into a WebEngine-instance, the "localStorage" (in JavaScript) will permanently become null.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      - create empty file on /tmp/foo.html (or change path, or use web URL)
      - make sure user-data-directory parent is writable (/tmp/java-store)
      - run main in LocalStorageBugDemo (which reads localStorage, "closes" window and reads storage again)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      localStorage before close is: [object Storage]
      localStorage before close is: [object Storage]

      ACTUAL -
      localStorage before close is: [object Storage]
      localStorage after close is: null

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.concurrent.Worker;
      import javafx.scene.web.WebEngine;
      import javafx.scene.web.WebView;
      import javafx.stage.Stage;

      import java.io.File;

      public class LocalStorageBugDemo extends Application {

          public static void main(String[] args) {
              launch(args);
          }

          @Override
          public void start(final Stage stage) {
              final WebView webView = new WebView();
              final WebEngine webEngine = webView.getEngine();
              webEngine.setJavaScriptEnabled(true);
              webEngine.setUserDataDirectory(new File("/tmp/java-store"));

              webEngine.load("file:///tmp/foo.html");
              webEngine.getLoadWorker().stateProperty().addListener((observable, oldValue, newState) -> {
                          if (newState == Worker.State.SUCCEEDED) {
                              System.out.println("localStorage before close is: " + webEngine.executeScript("localStorage;"));
                              webEngine.executeScript("window.close();");
                              System.out.println("localStorage after close is: " + webEngine.executeScript("localStorage;"));
                              Platform.exit();
                          }
                      }
              );
          }
      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            • Assignee:
              ajoseph Arun Joseph
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: