CRAlpha / react-native-wkwebview

WKWebview Component for React Native
MIT License
642 stars 271 forks source link

Should set web view's config "allowFileAccessFromFileURLs" to true #106

Open boundaryfree opened 6 years ago

boundaryfree commented 6 years ago

like this; [_webview.configuration.preferences setValue:@(true) forKey:@"allowFileAccessFromFileURLs"];

So when load local file, it can access all the resources in "allowingReadAccessToURL" folder.

In my project, the js code (loaded by the web view) reference one html file. If not set the config "allowFileAccessFromFileURLs", the html file can not be accessed with the error: "XMLHttpRequest cannot load the referenced html file path. Cross origin requests are only supported for HTTP."

insraq commented 6 years ago

Have you tried setting this prop in source: source={{file: '', allowingReadAccessToURL: '' }}

JakeRawr commented 6 years ago

Could be similar issue to this.

In my HTML files, I load bundle.js using <script src="bundle.js"></script> the js file doesn't seems to run

here's my code

source={{ file: RNFS.MainBundlePath + '/index.html', allowingReadAccessToURL: RNFS.MainBundlePath}}

And I've checked the RNFS.MainBundlePath, both index.html and bundle.js are in there

InternetExplorer8 commented 6 years ago

@boundaryfree can you create a pull request?

shoebhoney commented 4 years ago

@boundaryfree @insraq @JakeRawr @InternetExplorer8 any luck? I also need to use - allowFileAccessFromFileURLs And source={{ file: RNFS.MainBundlePath + '/index.html', allowingReadAccessToURL: RNFS.MainBundlePath}} Its NOT WORKING. :(