WebKit will not allow http to be registered as a local URL scheme

WebKit has a +[WebView registerURLSchemeAsLocal:] method. This is quite handy if you’re implementing a custom URL scheme in your app that WebKit needs to refer to; but as I’ve found, it’s not good for anything else.

Here’s the problem: Sandvox builds HTML pages for editing. Those pages are supposed to be as close to the published content as possible. Ideally, they’d load with the page’s final location as the base URL so that custom content like Google Ads would know how to display.

If you specify an HTTP base URL, WebKit will interpret those resources correctly, yes, but will no longer load any local content since HTTP is a remote scheme. Easily solved you think, register @“http” as a local scheme!

[WebView registerURLSchemeAsLocal:@“http”];

No exceptions are thrown or any other complaint made by WebKit, but this has absolutely zero effect. Why? Well, fortunately WebKit is open-source so we can have a poke around. Turns out WebKit is hardcoded (for performance reasons) to never treat HTTP as a local scheme.

So that puts paid to that plan.

© Mike Abdullah 2007-2015