breautek commented on issue #1610: URL: https://github.com/apache/cordova-android/issues/1610#issuecomment-1529577540
Testing via https://socketsbay.com/test-websockets shows websockets are working for me. ### Note on CSP Cordova's default configuration doesn't allow websocket connections, but you'll get an CSP (Content Security Policy) error for that. At minimum, you'll need to add to your `<meta http-equiv="Content-Security-Policy"`: ``` connect-src: ws: wss:; ``` Ideally you'd include the full domain + port to limit connects to a specific server. ### Note on Secure Connections I'm unable to test `ws` protocol specifically, however this would yield a connection error (at least it does for XHR...) But both the android platform and browsers generally forbid non-secure protocols by default, with some exceptions (e.g. I think `localhost` is allowed on browsers). The android platform (including completely native apps) by default forbids all insecure connection types. It would be recommended to use `wss://` if possible. If this is a local test server, then you may be able to work around it by declaring that you use [cleartext](https://cordova.apache.org/docs/en/11.x/guide/platforms/android/index.html#android-quirks) traffic. This should be used for your development environment only. Inside the `config.xml`: ```xml <platform name="android"> <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application"> <application android:usesCleartextTraffic="true" /> </edit-config> </platform> ``` If the `config.xml` doesn't declare the `android` namespace already, you'll also need to add `xmlns:android="http://schemas.android.com/apk/res/android"` to the root `widget` tag. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
