简体   繁体   English

WebView (react-native-webview) 在 Expo SDK36 中获取错误代码 -1

[英]WebView (react-native-webview) getting error code -1 in Expo SDK36

My Expo App's WebViewScreen Code:我的 Expo 应用程序的 WebViewScreen 代码:

import React from 'react';
import { WebView } from 'react-native-webview';

export default WebViewScreen = () => (
    <WebView
        originWhitelist={['*']}
        source={{ uri: 'https://www.google.com' }}
    />
);

but when i run it, i get following error:但是当我运行它时,我收到以下错误:

Encountered an error loading page, Object {
  "canGoBack": false,
  "canGoForward": false,
  "code": -1,
  "description": "net::ERR_CACHE_MISS",
  "loading": false,
  "target": 3,
  "title": "Web page not available",
  "url": "https://www.google.com/",
}

NOTE:笔记:
My Android phone is connected to wifi, and I am able to consume backend-server APIs almost on every screen in my Expo app, which confirms that internet is reachable and my app has the permission to use internet .我的 Android 手机已连接到 wifi,并且我几乎可以在我的 Expo 应用程序的每个屏幕上使用后端服务器 API,这证实了Internet 可以访问并且我的应用程序有权使用 internet

My Environment:我的环境:
Android Samsung phone (Android version 5.1.1), Android 三星手机(Android 版本 5.1.1),
EXPO SDK version is 36, EXPO SDK版本为36,
react-native-webview version 8.0.6, react-native-webview版本 8.0.6,
Expo client app version 2.14.0 Expo 客户端应用程序版本 2.14.0

PS: PS:
For react-native-webview ,对于react-native-webview
I did NOT do npm install --save react-native-webview ,我没有做npm install --save react-native-webview
instead, i did expo install react-native-webview with expo-cli version 3.11.7相反,我使用expo-cli版本 3.11.7 expo install react-native-webview

PPS: I tried running the expo snack of webview from here (official?) on my phone via QR code scan, yet got the same error ( "code": -1 ) . PPS:我尝试通过二维码扫描从这里(官方?)在我的手机上运行 webview 的 expo 小吃,但得到了同样的错误( "code": -1

Can someone guide how to get rid of this error and get the webview up and running?有人可以指导如何摆脱这个错误并使 webview 启动并运行吗?

Did you set the right permission in your manifest?您是否在清单中设置了正确的权限?

<uses-permission android:name="android.permission.INTERNET"/>

In your case it should be the App.json file在您的情况下,它应该是 App.json 文件

Did you try the temporary fix posted here ?您是否尝试过此处发布的临时修复程序?

They say that there could be a problem with the websites service workers (due to a bug in Chrome 75).他们说网站服务人员可能有问题(由于 Chrome 75 中的错误)。

The solution involves injecting this JS script to the WebView , to unregister the stalled service workers:解决方案包括将此 JS 脚本注入WebView ,以取消注册停滞的服务工作者:

navigator.serviceWorker.getRegistrations().then(function(registrations) {
    for (let registration of registrations) {
        registration.unregister();
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM