title: How to set sessionStorage before UIWebView loads request?
body: <p><strong>Code</strong></p>
  
  <p>Here is what I've been trying to do:</p>
  
  <pre><code>import UIKit
  import WebKit
  
  class WebViewViewController: UIViewController {
      @IBOutlet weak var webView: UIWebView!
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          let url = NSURL(string: "http://example.com/index.html")
          webView.stringByEvaluatingJavaScript(from: "sessionStorage.setItem('exampleKey','exampleValue');")
          let request = URLRequest(url: url! as URL)
          webView.loadRequest(request)
      }
  }
  </code></pre>
  
  <p><strong>Problem</strong></p>
  
  <p>However, when looking the console in Safari for the Simulator sessionStorage does not contain <code>exampleKey</code>.</p>
  
  <p><strong>Question</strong></p>
  
  <p>How can I set the sessionStorage before loading <code>http://example.com/index.html</code>?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Solution proposed by Alexandre Lara does not work for me.</p>
  
  <pre><code>import UIKit
  import WebKit
  
  class WebViewViewController: UIViewController, UIWebViewDelegate {
      @IBOutlet weak var webView: UIWebView!
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          let url = NSURL(string: "http://example.com/index.html")
          let request = URLRequest(url: url! as URL)
          webView.delegate = self
          webView.loadRequest(request)
      }
  
      func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -&gt; Bool {
          webView.stringByEvaluatingJavaScript(from: "sessionStorage.setItem('exampleKey','exampleValue');")
          return true
      }
  }
  </code></pre>