Our game requires that we provide an API for embedded web apps to interact with game data. We’d like a portion of this API to be authored as custom URL schemes that can be authored in HTML, for example - `<img src=“my-game://image/{contentId}” />` would allow C++ game code to look up the corresponding asset and stream an image to the browser.
This works well on Win64 by implementing the `IWebBrowserSchemeHandler` and `IWebBrowserSchemeHandlerFactory` APIs, but unfortunately these aren’t implemented on Android and iOS.
The workaround for mobile is to either pass Base64 strings to the web page (expensive for CPU and memory) or use `file://` origins (security/CORS issues on mobile).
In `WebBrowserSingleton.cpp`, the implementation for `RegisterSchemeHandlerFactory` is wrapped with an `#if WITH_CEF3` block. On mobile platforms, the native web view wrappers don’t consult the engine’s scheme registery, making it impossible to intercept and serve local binary data directly to a web page via a custom scheme.
Locally we’ve been able to modify the various browser-related classes to enable this natively:
- Remove the `#if WITH_CEF3` guard in `WebBrowserSingleton.cpp` and expose a lookup API for platform-specific widgets to query registered factories
- Patched `SAndroidWebBrowserWidget::HandleShouldInterceptRequest` to check the scheme against the C++ registry, execute the `IWebBrowserSchemeHandler` and stream the results back into the JNI `WebResourceResponse`
- We haven’t implemented this locally yet, but we plan to use the `WKURLSchemeHandler` protocol in `ApplePlatformWebBrowser.cpp` to bridge the native `WKWebView` requests back to the C++ registery
Before we continue investing more into this, I wanted to check to see if there are there plans on Epic side to eventually implement this behavior natively for mobile web views?
[Attachment Removed]