-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<img> in webview works on iOS emulator, fails on iOS device #6377
Comments
Hi @dlcole,
|
See Manoj's response at https://stackoverflow.com/questions/52712839/img-in-webview-works-on-ios-emulator-fails-on-ios-device/52748358#52748358 - this is still looking like a {N} bug, methinks. |
I have a similar problem, when I'm loading html file contents load correctly(html code) but assets like a photo javascript and css doesn't load. I try load assets from different paths in src attribute, eg.
but nothing works. |
Hi, This problem is a blocker for me, I have some html content embedded into the app (for presentation), wright now I can not update from version 3.2, because of that nasty bug. Many thanks! |
@pawel-filuciak - sorry you're having this problem, too. I have been unable to find a workaround. I agree this is a problem that really needs to be fixed. |
Hi all, |
Hi, |
Hi @gregorywojcik, |
@gregorywojcik - thank you so much. I have just tried your solution and it worked perfect on Iphone |
@gregorywojcik - your patch looks useful thanks for offering it! But, it requires that the local file have a full file:/// prefix, which precludes use of relative paths, which is what I really need. |
@dlcole |
@NickIliev This issue is not just limited to image tag but loading any resources (JS / CSS / Images etc.,) from the same folder where |
Fixes loading of html dependencies when loading a local file to web view. I've just implemented the code changes in the patch provided by @gregorywojcik [here](NativeScript#6377 (comment)) references NativeScript#6377
Fixes loading of html dependencies when loading a local file to web view. I've just implemented the code changes in the patch provided by @gregorywojcik [here](#6377 (comment)) references #6377
This problem is still not fixed for me. My code has the html defined as part of the viewModel (i.e., not a standalone file). From within the html I reference images I want to include, such as
As I mentioned in my original post, this works on Android, and I need a single format that works on both Android and iOS. It appears the fix only works where you're loading a static html file with resources in the same folder. :-( |
@dlcole I think that was the intention, iOS web view can load the assets only from the whitelisted directory, when you pass HTML string it's impossible to know from which directories it's going to load the assets. You might want to log a new issue for exposing a new property on WebView class to set the list of directories to whitelist. |
@manojdcoder Your comment made me think that if I moved the images to the app folder, which would surely be whitelisted, then perhaps this could work. So, I changed the img tag to be:
But that fails on both Android and iOS. Do you think this is really just a whitelisting issue? |
@manojdcoder So I added code to copy my images to the temp folder, write the html source to a file in the temp folder, and changed the src attribute to point to the file. Good news! This now works on iOS devices, as I expected given the fix described above. Now for the bad news: this does not work on Android :-(. So, where I now have
the image file is not found. |
Oops - spoke too early! My code wasn't overwriting the html file, so it wasn't picking up my source changes on Android. This approach does indeed work on both iOS and Android. Yay! |
@dlcole @gregorywojcik I'm still a bit confused about the status of this issue? @gregorywojcik do you plan to submit a PR to have this feature officially merged in? I haven't tried this patch yet but was wondering if I should wait until there is an official fix. Thanks for the great work everyone. |
@gregorywojcik @imerljak sorry for the bonehead response above. Didn't realize this fix was in fact merged. Unfortunately It's still not working for me. I'm using NativeScript Vue and wondering if that might be the issue. Similar to @tzydo I tried putting the file in different folders with no success. My app is super basic as this point more or less the boilerplate generated from the CLI so I doubt it could be a plugin issue. I've tested on both the ios Simulator and on my iphone via tns preview. All I get is a black screen |
@EddyVerbruggen @imerljak @manojdcoder Once curious this I did notice is that if if set the src to "~/test.html" instead of a blank page the webview interprets this path as a the html content and just render ~/test.html to the page as plain text. |
I was able to get help on from @rigor789 on slack. I needed add my html paths to the copy plugin in webpack config. new CopyWebpackPlugin([ |
Good morning, people. |
Ok, fixed. Don't know why but it was something to do with double-quotes character. I was supposed to be using double quotes, then I changed to single quotes and finally I simply copy the quotes character from other text. So the solution was simply using this: Worked well in both, iphone simulator and genymotion (android). |
For people struggling with this issue: the solution mentioned by @hraynaud workedfor me in all instances. So, it might be a good idea checking the globs on CopyWebpackPlugin in the webpack.config.js file:
|
Added advice -- the of CopyWebpackPlugin globs -- to mitigate errors in loading local src files because they were not copied to from the source code as mentioned on NativeScript/NativeScript#6377 (comment)
Added advice -- the of CopyWebpackPlugin globs -- to mitigate errors in loading local src files because they were not copied to from the source code as mentioned on NativeScript/NativeScript#6377 (comment)
Environment
Provide version numbers for the following components (information can be retrieved by running
tns info
in your project folder or by inspecting thepackage.json
of the project):✔ Component nativescript has 4.2.4 version and is up to date.
✔ Component tns-core-modules has 4.2.1 version and is up to date.
✔ Component tns-android has 4.2.0 version and is up to date.
✔ Component tns-ios has 4.2.0 version and is up to date.
Describe the bug
A simple webview with an image in a local folder is not loaded on an iOS device, but is loaded on an iOS simulator and on Android devices and simulator.
To Reproduce
Create a webview, include an tag and set the src= property to a local folder, i.e,
<img src="./marker_r.png" >
An external image will display properly on an iOS device, a local image will not.
Expected behavior
Image is shown as it is on Android and an iOS simulator
Sample project
https://play.nativescript.org/?template=play-js&id=2Jslpt&v=7
(Note that playground project does not include image file in local folder, but does show what attempts have failed)
Additional context
This appears to be identical to #4443 but yet the problem persists with the latest NativeScript code.
Also posted at https://stackoverflow.com/questions/52712839/img-in-webview-works-on-ios-emulator-fails-on-ios-device
The text was updated successfully, but these errors were encountered: