title: WKWebView XMLHttpRequest fails with custom url scheme
body: <p>I'm building a mobile app using WKWebView. I register custom url schemes image:// and thumb:// to serve assets from the native part to the web part of the app.</p>
  <pre><code>webViewConfiguration.setURLSchemeHandler(handler, forURLScheme: &quot;image&quot;)
  webViewConfiguration.setURLSchemeHandler(handler, forURLScheme: &quot;thumb&quot;)
  </code></pre>
  <p>This approach works well if urls with a custom scheme are used in HTML. For example, <code>&lt;img src=&quot;thumb://watermarkly.com/1.jpg&quot; /&gt;</code> works properly - WKWebView invokes my handler and displays the result. However, WKWebView blocks requests if I try to fetch these urls using XMLHttpRequest:</p>
  <pre><code>[Warning] The page at https://watermarkly.com/app/watermark/ was allowed to display insecure content from thumb://watermarkly.com/1.jpg.
  
  [Warning] [blocked] The page at https://watermarkly.com/app/watermark/ was not allowed to display insecure content from image://watermarkly.com/1.jpg.
  
  [Error] Not allowed to request resource
  
  [Error] XMLHttpRequest cannot load image://watermarkly.com/1.jpg due to access control checks.
  </code></pre>
  <p>The only difference here is that &quot;thumb:&quot; url was assigned to an img tag, while &quot;image:&quot; url were fetched via XMLHttpRequest. Unfortunately, no other info provided in Safari Developer Tools.</p>
  <p>The problem appears on a real devices only - everything works properly in iOS Simulator.</p>
  <p>Is there something I need to configure to make it work for XMLHttpRequests as well?</p>
  <h2>Update</h2>
  <p>We switched from HTTPS to HTTP to make XHR to solve the problem.</p>
  <p>Unfortunately, custom url schemes seems not to work on some iPhones. We have 5 customers with iPhones where nor switching to HTTP, nor sending Access-Control-Allow-Origin header help. We weren't able to identify which setting causes the issue - the problem cannot be reproduced on any of devices we have. Apple reviewer didn't have any complaints as well. Nor XHR, not getting images through urls work on these phones. One of the customers has two phones. Custom url schemes work on one of them and they don't work on the second one at all. He says they are identical and there is no Safari extensions installed. Unfortunately, we weren't able to identify what causes the problem. Beware custom url schemes may not work on some phones.</p>