React Native:Android WebView为某些网站和某些设备返回空白屏幕 [英] React Native: Android WebView returns blank screen for some websites and some devices

查看:230
本文介绍了React Native:Android WebView为某些网站和某些设备返回空白屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有效的反应原生应用程序,用了一个WebView指向HTTPS站点几个月。
这一切都运行良好,但突然WebView开始返回空白页而不是HTTPS站点。

I've got a working react-native app for quite a few months with a WebView directing to an HTTPS site. This was all working great, but suddenly the WebView start returning a blank page instead of the HTTPS site.

从调试开始,我发现:

From debugging, I've found out that:


  • 这种情况只发生在我的设备上(我的用户没有报告此问题)

  • This happens only on my device (non of my users have reported this issue)

某些网站会返回空白屏幕,对于某些网站,它会正确呈现。 (例如google.com会渲染,amazon.com会返回一个空白屏幕)

Blank screen is returned for some websites, and for some it renders correctly. (e.g. google.com would render and amazon.com would return a blank screen)

从调试Chrome检查器中的WebView看起来每次都是GET调用已经对其中一个网站(例如amazon.com)进行了调用,在1秒左右后,该呼叫被取消。

From debugging the WebView in chrome inspector it seems like every time a GET call has been made to one of theses sites (e.g. amazon.com) the call gets cancelled after 1 second or so.

这些网站被调用,打开并呈现正确地在我的android-chrome浏览器上。

These sites are called, opened and rendered correctly on my android-chrome browser.

似乎我的设备中的某些内容阻止了WebView中的某些网站,也许是设置或应用程序。它可能是什么?

Seems like something in my devices is blocking some websites in WebViews, perhaps a settings, or an app. What could it be?

我正在使用LG G4,在API版本19和23上试用。

I'm using LG G4, tried on API version 19 and 23.

推荐答案

必须是因为开发模式下的私有SSL错误。如果您将看到控制台日志处于调试模式,那么您可以看到一行说明
无法验证证书链,错误:java.security.cert.CertPathValidatorException:认证路径的信任锚没有找到。

It must be because of private SSL error in development mode. If you will see the console log in debug mode then you can see a line saying Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

如果是,那么只需添加一个新的道具,在文档的任何地方都没有提到。道具是 ignoreSslError = {true} ,这将强制WebView加载网站,尽管SSL出错。

If yes then just add a new prop which is not mentioned anywhere in the doc. The prop is ignoreSslError={true} which will force the WebView to load the website despite of SSL error.

Ex -
< WebView ignoreSslError = {true} source = {{uri:'https://www.google.com'}} />

资料来源: https:// github.com/facebook/react-native/pull/9680

这篇关于React Native:Android WebView为某些网站和某些设备返回空白屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆