WKURLSchemeHandler and fetch requests with custom scheme

239 Views Asked by At

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. I've also searched around and it seems like, at least at one point in time, other developers have been able to handle fetch/XHRs with the custom scheme handler.

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

I've attempted to add my custom scheme to all of the CSP sources (this was necessary for img-src to get img tags to load from this scheme) but this didn't seem to have any effect.

I've attempted to set allowUniversalAccessFromFileURLs to true on my webview configuration. This appears to have helped others, but has had no effect for me.

0

There are 0 best solutions below