4

My Expo App's WebViewScreen Code:

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.

My Environment:
Android Samsung phone (Android version 5.1.1),
EXPO SDK version is 36,
react-native-webview version 8.0.6,
Expo client app version 2.14.0

PS:
For react-native-webview,
I did NOT do npm install --save react-native-webview,
instead, i did expo install react-native-webview with expo-cli version 3.11.7

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).

Can someone guide how to get rid of this error and get the webview up and running?

FAQi
  • 865
  • 1
  • 13
  • 21

2 Answers2

0

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

BR75
  • 633
  • 7
  • 25
  • In Expo Apps, `app.json` does not contain any `````` tag, I have read official docs about Expo's app.json [here](https://docs.expo.io/versions/latest/workflow/configuration). Interestingly I found there that **"To use ALL permissions supported by Expo, do not specify the "permissions" key."**, which i have not. For some permissions I am explicitly asking user for Camera/Location permissions during runtime. **Also please note** that I am able to consume backend-server APIs almost on every screen in my Expo app, which confirms that my app has the permission to use internet. – FAQi Feb 07 '20 at 05:16
0

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).

The solution involves injecting this JS script to the WebView, to unregister the stalled service workers:

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