title: javascript embedded in html not running in wkwebview
body: <p>I am implementing wkwebview in an app that was using UIWebView. I am unable to get javascript to execute when pointing to a local html file that has the javascript embedded within it. The javascript is stripped to do a simple alert and load a basic google map. None of that is getting executed. Do I need to run a local server? GCDWebserver..</p>
  
  <p>I should add, the html/javascript works in safari, google browser no problem.</p>
  
  <p>Solutions attempted include:
  1. AppTransportSecuritySettings AllowArbitrary loads.
  2. ViewController.swift webview.configuration.preferences.javaScriptEnabled = true
  3. This question addresses the issue and says is was fixed in iOS 10.3 <a href="https://stackoverflow.com/questions/45371386/load-javascript-files-through-html-file-on-wkwebview-in-ios">Load Javascript files through HTML file on WKWebView in iOS</a>  The simulator is running 12.1
  4. This question also addresses the issue with an answer of requiring GCDWebserver to be able to execute javascript using wkwebview. <a href="https://stackoverflow.com/questions/49170840/wkwebview-not-executing-any-js-code">WKWebView not executing any js code</a> This however was also solved in a laster version of iOS.  Here is some code:</p>
  
  <pre class="lang-swift prettyprint-override"><code>import UIKit
  import WebKit
  class ViewController: UIViewController, WKNavigationDelegate {
      //@IBOutlet var googleMap: WKWebView!
      var webview: WKWebView!
  
       override func loadView() {
           webview = WKWebView()
           webview.navigationDelegate = self
           view = webview
       }
      override func viewDidLoad() {
          super.viewDidLoad()
          //let url = URL(string: "https://schallerf1.com")!
          let url = Bundle.main.url(forResource: "index", withExtension: "html", subdirectory: "www")!
          webview.load(URLRequest(url: url))
          webview.allowsBackForwardNavigationGestures = true
          let request = URLRequest(url: url)
          webview.configuration.preferences.javaScriptEnabled = true
          webview.load(request)
      }
  }
  </code></pre>
  
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Simple Map&lt;/title&gt;
          &lt;meta name="viewport" content="initial-scale=1.0"&gt;
              &lt;meta charset="utf-8"&gt;
                  &lt;style&gt;
                      /* Always set the map height explicitly to define the size of the div
                       * element that contains the map. */
                  #map {
                      height: 100%;
                  }
                  /* Optional: Makes the sample page fill the window. */
                  html, body {
                      height: 100%;
                      margin: 0;
                      padding: 0;
                  }
                  &lt;/style&gt;
                  &lt;/head&gt;
      &lt;body&gt;
          &lt;b&gt;WHYYYYYYYYYY!!!!&lt;/b&gt;
          &lt;div style="height:100%;width:100%;" id="map"&gt;&lt;/div&gt;
          &lt;script type="text/javascript"&gt;
              var name = "TESTTESTTEST";
              alert('code: '    + name + '\n');
              var map;
              function initMap() {
                  map = new google.maps.Map(document.getElementById('map'), {
                                            center: {lat: 39.976068, lng: -83.003297},
                                            zoom: 8
                                            });
              }
          &lt;/script&gt;
          &lt;script async defer src="https://maps.googleapis.com/maps/api/js?key=xxxxxxxxxxxxxxxxxx&amp;callback=initMap"&gt;&lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>None of the javascript works, I should get an alert and a simple google map should display. Do I need to look into the local web server GCDWebserver?</p>