react-native-signalr
react-native-signalr copied to clipboard
TypeError: Cannot set property userAgent of #<Navigator> which has only a getter
Hi, I am getting "TypeError: Cannot set property userAgent of #<Navigator> which has only a getter" on line 15 of index.js file.
Below line is from the \node_modules\react-native-signalr\src\index.js file where i am getting the error. window.navigator.userAgent = window.navigator.userAgent || "react-native";
I am trying to create an android app using expo. I get this error when testing in the browser. Below is code from my App.js file:
` import React from "react" import { StyleSheet, View, Text } from "react-native" import signalr from "react-native-signalr"
let isConnected = "no"
export default class App extends React.Component {
async componentDidMount() {
try {
const connection = signalr.hubConnection("replace with signalr URL")
connection.logging = true
connection.start().done(function () {
isConnected = "connected"
})
connection.error((error) => {
const errorMessage = error.message;
let detailedError = "";
if (error.source && error.source._response) {
detailedError = error.source._response;
}
if (detailedError === "An SSL error has occurred and a secure connection to the server cannot be made.") {
console.log("When using react-native-signalr on ios with http remember to enable http in App Transport Security https://github.com/olofd/react-native-signalr/issues/14")
}
console.debug("SignalR error: " + errorMessage, detailedError)
});
} catch (e) {
console.log(e)
}
}
render() {
return (
<View style={styles.container}>
<Text style={[styles.trackInfoText, styles.largeText]}>
SignalR status: {isConnected}
</Text>
</View>
)
}
}
const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#fff", alignItems: "center", justifyContent: "center" }, albumCover: { width: 250, height: 250 }, trackInfo: { padding: 40, backgroundColor: "#fff" },
trackInfoText: {
textAlign: "center",
flexWrap: "wrap",
color: "#550088"
},
largeText: {
fontSize: 22
},
smallText: {
fontSize: 16
},
control: {
margin: 20
},
controls: {
flexDirection: "row"
}
})
`
Thanks, Ahmed
Did you ever find a solution to this issue @apanchati ? I am seeing a similar issue using react-native-web