title: Partially replace WebView content while it is loading
body: <p>The thing i want to do is to replace some part(s) of the web page HTML content (that is currently getting loaded inside WebView engine) with my own HTML content.</p>
  
  <p>As a simple example - i want to replace every loaded page body's background color to RED. Meaning i will need to add or replace existing body bgcolor attribute with my own value. What should i do to achieve that?</p>
  
  <p>Here is the basic browser code based on JavaFX WebView component:</p>
  
  <pre><code>public class BrowserTest extends Application
  {
      public static void main ( String[] args )
      {
          launch ( args );
      }
  
      public void start ( Stage stage )
      {
          stage.setTitle ( "WebView" );
  
          Browser browser = new Browser ();
          browser.load ( "http://google.com" );
  
          Scene scene = new Scene ( browser );
          stage.setScene ( scene );
  
          stage.show ();
      }
  
      public class Browser extends Region
      {
          final WebView browser;
          final WebEngine webEngine;
  
          public Browser ()
          {
              super ();
              browser = new WebView ();
              webEngine = browser.getEngine ();
              getChildren ().add ( browser );
          }
  
          public void load ( String url )
          {
              webEngine.load ( url );
          }
  
          private Node createSpacer ()
          {
              Region spacer = new Region ();
              HBox.setHgrow ( spacer, Priority.ALWAYS );
              return spacer;
          }
  
          protected void layoutChildren ()
          {
              double w = getWidth ();
              double h = getHeight ();
              layoutInArea ( browser, 0, 0, w, h, 0, HPos.CENTER, VPos.CENTER );
          }
  
          protected double computePrefWidth ( double height )
          {
              return 750;
          }
  
          protected double computePrefHeight ( double width )
          {
              return 500;
          }
      }
  }
  </code></pre>
  
  <p>There was a good example of this technique in some Oracle docs but since last JavaFX and site updates i couldn't find it at all. Maybe anyone has the link to old docs...</p>
  
  <p><strong>Note:</strong> Also <strong>jewelsea</strong> offered a good way to make post-changes (when the page is loaded), but i need exactly "load-while" solution for my case, so that WebView won't do double job rendering page twice (before and after changes).</p>