title: Clear the session/cache/cookie in the JavaFX WebView
body: <p>I had a Swing dialog, which uses JavaFX <code>WebView</code> to display oAuth 2.0 URL from Google server.</p>
  
  <pre><code>public class SimpleSwingBrowser extends JDialog {
  
      private final JFXPanel jfxPanel = new JFXPanel();
      private WebEngine engine;
  
      private final JPanel panel = new JPanel(new BorderLayout());
  
      public SimpleSwingBrowser() {
          super(MainFrame.getInstance(), JDialog.ModalityType.APPLICATION_MODAL);
          initComponents();
      }
  
  
      private void initComponents() {
          createScene();
  
          panel.add(jfxPanel, BorderLayout.CENTER);
  
          getContentPane().add(panel);
  
          java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
          setBounds((screenSize.width-460)/2, (screenSize.height-680)/2, 460, 680);
      }
  
      private void createScene() {
  
          Platform.runLater(new Runnable() {
              @Override 
              public void run() {
  
                  final WebView view = new WebView();
                  engine = view.getEngine();
  
                  engine.titleProperty().addListener(new ChangeListener&lt;String&gt;() {
                      @Override
                      public void changed(ObservableValue&lt;? extends String&gt; observable, String oldValue, final String newValue) {
                          SwingUtilities.invokeLater(new Runnable() {
                              @Override 
                              public void run() {
                                  SimpleSwingBrowser.this.setTitle(newValue);
                              }
                          });
                      }
                  });
  
                  engine.getLoadWorker()
                          .exceptionProperty()
                          .addListener(new ChangeListener&lt;Throwable&gt;() {
  
                              public void changed(ObservableValue&lt;? extends Throwable&gt; o, Throwable old, final Throwable value) {
                                  if (engine.getLoadWorker().getState() == FAILED) {
                                      SwingUtilities.invokeLater(new Runnable() {
                                          @Override public void run() {
                                              JOptionPane.showMessageDialog(
                                                      panel,
                                                      (value != null) ?
                                                      engine.getLocation() + "\n" + value.getMessage() :
                                                      engine.getLocation() + "\nUnexpected error.",
                                                      "Loading error...",
                                                      JOptionPane.ERROR_MESSAGE);
                                          }
                                      });
                                  }
                              }
                          });
  
                  // http://stackoverflow.com/questions/11206942/how-to-hide-scrollbars-in-the-javafx-webview
                  // hide webview scrollbars whenever they appear.
                  view.getChildrenUnmodifiable().addListener(new ListChangeListener&lt;Node&gt;() {
                      @Override 
                      public void onChanged(Change&lt;? extends Node&gt; change) {
                          Set&lt;Node&gt; deadSeaScrolls = view.lookupAll(".scroll-bar");
                          for (Node scroll : deadSeaScrolls) {
                              scroll.setVisible(false);
                          }
                      }
                  });
  
                  jfxPanel.setScene(new Scene(view));
              }
          });
      }
  
      public void loadURL(final String url) {
          Platform.runLater(new Runnable() {
              @Override 
              public void run() {
                  String tmp = toURL(url);
  
                  if (tmp == null) {
                      tmp = toURL("http://" + url);
                  }
  
                  engine.load(tmp);
              }
          });
      }
  
      private static String toURL(String str) {
          try {
              return new URL(str).toExternalForm();
          } catch (MalformedURLException exception) {
                  return null;
          }
      }
  }
  </code></pre>
  
  <p>Everytime, I will get the following URL from Google. I will use the <code>SimpleSwingBrowser</code> to load the following URL.</p>
  
  <p><a href="https://accounts.google.com/o/oauth2/auth?client_id=xxx&amp;redirect_uri=http://localhost:55780/Callback&amp;response_type=code&amp;scope=email%20https://www.googleapis.com/auth/drive.appdata%20profile" rel="noreferrer">https://accounts.google.com/o/oauth2/auth?client_id=xxx&amp;redirect_uri=http://localhost:55780/Callback&amp;response_type=code&amp;scope=email%20https://www.googleapis.com/auth/drive.appdata%20profile</a></p>
  
  <p>During the <strong>first time</strong>, the following UI will be shown.</p>
  
  <h2>Screen One</h2>
  
  <p><img src="https://i.stack.imgur.com/9rLXD.png" alt="enter image description here"></p>
  
  <h2>Screen Two</h2>
  
  <p><img src="https://i.stack.imgur.com/jej8M.png" alt="enter image description here"></p>
  
  <p>After I </p>
  
  <ol>
  <li>Perform success login at Screen One.</li>
  <li>Presented with Screen Two.</li>
  <li>Click on Accept.</li>
  <li>Close the web browser dialog.</li>
  <li>Again, generate the exact same URL as first time.</li>
  <li>Create a completely new instance of <code>SimpleSwingBrowser</code>, to load URL generated at step </li>
  </ol>
  
  <p>I expect Google will show me Screen One again, as this is a new browsing session. However, what I'm getting for the 2nd time, is Screen Two.</p>
  
  <p>It seems that, there are some stored session/cache/cookie in the <code>WebView</code>, even though it is a completely new instance.</p>
  
  <p>I expect I will get myself back to Screen One, so that I can support multiple user accounts.</p>
  
  <p>How can I clear the session/cache/cookie in the <code>WebView</code>?</p>