WebView can't showing login js pupup "basic auth" in react-native

467 Views Asked by At

I am trying to open this page to test NTLM login in my react-native app:

link: https://authenticationtest.com/HTTPAuth/

the code:

return (
    <View style={styles.root}>
      <View>
        <ProgressBar
          progress={loadingProgress}
          color={theme.palette.primary.main}
          visible={loadingProgress < 1}
        />
      </View>

      <WebView
        source={{ uri: 'https://authenticationtest.com/HTTPAuth/'}}
        useWebView2={true}
        javaScriptEnabled={true}
        domStorageEnabled={true}
        javaScriptCanOpenWindowsAutomatically={true}
        style={styles.container}
        useWebKit
        sharedCookiesEnabled={true}
        incognito={true}
        startInLoadingState={true}
        setSupportMultipleWindows={false}
        onLoadProgress={({ nativeEvent }) => {
          setLoadingProgress(nativeEvent.progress);
        }}

      />
    </View>
);

I used javaScriptEnabled={true} but didn't worked..

1

There are 1 best solutions below

3
Vasyl Nahuliak On

Code:

import { SafeAreaView, StyleSheet } from 'react-native';
import WebView from 'react-native-webview';

const username = 'user';
const password = 'pass';

export default function App() {
  return (
    <SafeAreaView style={styles.container}>
      <WebView
        source={{
          uri: `https://${username}:${password}@authenticationtest.com/HTTPAuth/`,
        }}
        style={styles.container}
      />
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});

Online playground: https://snack.expo.dev/@vasylnahuliak/76295278

Source workaround: https://github.com/react-native-webview/react-native-webview/issues/18#issuecomment-532859482