Hello. I’m loading a local HTML file using file:// source in a webview. The file loads fine, but scripts in the file fail to request external URLs (API responses and fonts) with
Access to XMLHttpRequest at 'https://[redacted]' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I can’t find any WebView prop to ignore CORS rendering file:// pages:
allowFileAccess={true} nor mixedContentMode='always' change anything
onShouldStartLoadWithRequest doesn’t seem like a relevant prop
Am I missing something? What’s an expected handling of CORS/HTTP requests from a file:// in a webview?
App Name: Not yet submitted App Link on Amazon Appstore (found through Developer Console > Actions column in App List > View on Amazon.com): Not yet submitted
We probably could make that work, although it won’t be trivial. Pages in the WebView are already used on other platforms and make requests predominantly through @tanstack/query and I can see only two approaches of using a bridge:
RN makes requests on its own (based on WebView’s URL) and pushes the data into query’s cache
A lot of duplication and tight coupling between RN and WebView’s contents
Replace WebView’s API calls (XHR via axios and HLS.js) with postMessage+onMessage (+injectJavaScript?)
Maintaining the same Promise-based API when multiple in-flight requests would be a challenge
Won’t help with the fonts, but that’s minor as we indeed could keep using bundled fonts (instead of overwriting them with the latest remote version)
That would require (production) API endpoints to accept localhost requests, which I’m hesitant about. Although that localhost server could probably also be a proxy for API requests?..
All and all, the approach seems the most promising but wasteful (but maybe it’s common in RN ecosystem? Vega is the first time I’m dabbling in RN)