title: Change User-Agent for AJAX calls from Delphi TWebBrowser
body: <p>I have a Delphi application that loads the Google Maps JavaScript API in an embedded web browser. The page it loads looks like this:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&gt;
      &lt;style&gt;
         #map {
          height: 400px;
          width: 100%;
         }
      &lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div id="map"&gt;&lt;/div&gt;
      &lt;script&gt;
        function initMap() {
          var map = new google.maps.Map(document.getElementById('map'), {});
        }
      &lt;/script&gt;
  
      &lt;script async defer
      src="https://maps.googleapis.com/maps/api/js?v=3.29&amp;key=~APIKEY~&amp;callback=initMap"&gt;
      &lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I'm displaying the page like this in a <code>TWebBrowser</code>:</p>
  
  <pre class="lang-pascal prettyprint-override"><code>str := StringReplace(htmlBase, '~APIKEY~', cMapsAPIKey, []);
  
  if not Assigned(WebBrowser.Document) then
    WebBrowser.Navigate('about:blank', '1', '', '', 'User-Agent: Mozilla/5.0');
  
  doc := WebBrowser.Document;
  doc.Clear;
  doc.Write(str);
  doc.Close;
  </code></pre>
  
  <p><code>TWebBrowser.Navigate()</code> will use the user agent string I've provided for the main page, but it uses this to load the scripts:</p>
  
  <blockquote>
    <p>User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; InfoPath.3)</p>
  </blockquote>
  
  <p>Starting with 3.29, the Google Maps JavaScript API seems to be checking the browser's user agent and displaying an error message: "You are using a browser that is not supported". This isn't an issue with 3.28 or below. The browser is supported (it's using IE 11), it's just sending the wrong user agent string.</p>
  
  <p>On the JavaScript end, how can I override the user agent check without disabling warnings completely? And on the Delphi end, is there a way to change the user agent for AJAX calls?</p>
  
  <p><strong>Edit</strong>: Overriding <code>TWebBrowser.Invoke()</code> lets me change the user agent for all HTTP requests, but it looks like <code>navigator.userAgent</code> isn't being changed.</p>