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

UserAgent blank when initially opening a WebView

XMLWordPrintable

    • web
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Using Azul Zulu 11.0.13 with OpenJFX, on Windows.
      Recreated in Azul Zulu 17.0.1

      Works fine on 11.0.9.1 (did not test other versions)

      A DESCRIPTION OF THE PROBLEM :
      When creating and opening a new webview, the first page loads without a user agent string, and I presume it lacks other relevant content. This could potentially break sites that adapt their content to the browser being used.


      REGRESSION : Last worked in version 11

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a new web view. Give it a URL to load. Add it to a scene. Put that scene on a screen.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The page loads, aware of the user agent being used.
      ACTUAL -
      The page reports that it wasn't given a user agent string. If you right click the page and choose 'Reload' the page will reload with the proper user-agent string.

      ---------- BEGIN SOURCE ----------
      package com.example.webviewbug;

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.layout.VBox;
      import javafx.scene.web.WebView;
      import javafx.stage.Stage;

      public class Launcher extends Application {

          private static String url = "https://www.whatismybrowser.com/";

          public static void main(String[] args) {
      if(args.length >0)
      url = args[0];
              launch(args);
          }

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

              WebView webView = new WebView();

              ////Hack used to hide the issue - load some other content first.
              //webView.getEngine().loadContent("<html><body></body></html>","text/html; charset=utf8");

              webView.getEngine().load(url);

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

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

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

      CUSTOMER SUBMITTED WORKAROUND :
      A) Reload the page after initially loading it - awkward, but may get existing software to work.
      B) Load some dummy content before providing the URL to load, eg:
          webView.getEngine().loadContent("<html><body></body></html>","text/html; charset=utf8");

      FREQUENCY : always


            pnarayanaswa Praveen Narayanaswamy
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: