WKURLSchemeHandler and fetch

I have an application that displays some HTML content with a WKWebView.

I'm using a WKURLSchemeHandler attached to the webview configuration to respond to requests for local resources.

This works as expected for img tags. I'm able to handle the requests for those images in my WKURLSchemeHandler instance and see the content displayed in the webview.

However, when I try to load a resource with my custom scheme using fetch() I consistently get 3 subsequent error messages in the safari dev console.

[blocked] The page at <my pages location> was not allowed to display insecure content from mycustomscheme://<some resource>

Not allowed to request resource

fetch cannot load mycustomscheme://<some resource> due to access control checks.

It seems to be ambiguous in the documentation for WKURLSchemeHandler whether it should be able to service requests from fetch and/or XMLHttpRequest.

Is this explicitly not supported or is there perhaps something I'm missing that would make this work?

I am trying to do the same thing. Could you share how you are using WKURLSchemeHandler? Thanks

I believe I know the root of this issue. In my case, the webview has its base URL set as a valid location, with a scheme of https. WKWebView sees custom schemes as insecure. WKWebView also does not allow pages loaded with a secure scheme to fetch from domains which are not secure.

If I set the base url of my page to nil or an http URL, fetch loads from the custom scheme handler as expected.

I haven't yet found any way to change the policy to allow the "insecure" fetch to proceed.

WKURLSchemeHandler and fetch
 
 
Q