You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "jmarshall-com (via GitHub)" <gi...@apache.org> on 2026/02/17 02:05:00 UTC
[I] WebSocket not opening with version 14.0.1, with simple test case [cordova-android]
jmarshall-com opened a new issue, #1881:
URL: https://github.com/apache/cordova-android/issues/1881
# Bug Report
## Problem
A call of `new WebSocket('wss://echo.websocket.org')` (a public testing server) results in its `onerror` handler being called, with an empty error message.
### What is expected to happen?
The websocket should open, and the `onopen` handler should be called
### What does actually happen?
The websocket does not open, and instead calls the `onerror` handler. `JSON.stringify()` of the error argument is `{"isTrusted":true}`.
## Information
<!-- Include all relevant information that might help understand and reproduce the problem -->
### Command or Code
This is the entire `index.js`:
```
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
const ws = new WebSocket('wss://echo.websocket.org');
ws.onopen = () => alert('WebSocket connected!') ;
ws.onerror = (error) => alert('WebSocket error: '+ JSON.stringify(error)) ;
ws.onclose = (event) => alert('WebSocket closed: '+ event.code+ event.reason) ;
}
```
The only other change I made after `cordova create` was to add `connect-src: *` to the CSP `<meta>` tag in `index.html`.
### Environment, Platform, Device
<!-- In what environment, on what platform or on which device are you experiencing the issue? -->
This is on a Mac mini, using an Android emulator from Android Studio.
### Version information
<!--
What are relevant versions you are using?
For example:
Cordova: Cordova CLI, Cordova Platforms, Cordova Plugins
Other Frameworks: Ionic Framework and CLI version
Operating System, Android Studio, Xcode etc.
-->
Cordova 12.0.0 (cordova-lib@12.0.2)
Cordova Android 14.0.1
no plugins
MacOS Tahoe 26.2
Android Studio: Panda 1 | 2025.3.1 Patch 1
Build #AI-253.29346.138.2531.14876573, built on February 11, 2026
Runtime version: 21.0.9+-14649483-b1163.86 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Android emulator: Pixel 7, Android 15.0, API 35
## Checklist
<!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
- [x] I searched for existing GitHub issues
- [x] I updated all Cordova tooling to most recent version
- [x] I included all the necessary information above
--
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: issues-unsubscribe@cordova.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [I] WebSocket not opening with version 14.0.1, with simple test case [cordova-android]
Posted by "jmarshall-com (via GitHub)" <gi...@apache.org>.
jmarshall-com commented on issue #1881:
URL: https://github.com/apache/cordova-android/issues/1881#issuecomment-3916747360
@GitToTheHub thanks for testing this. I changed my `connect-src` to `'self' https: wss:;` as you suggested but got the same results as with `*`. I've just created a github repo with the demo of the bug, as requested.
Out of curiosity, which desktop OS are you using? I'm using a Mac, which occasionally bites me by doing something unfamiliar.
--
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: issues-unsubscribe@cordova.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [I] WebSocket not opening with version 14.0.1, with simple test case [cordova-android]
Posted by "jmarshall-com (via GitHub)" <gi...@apache.org>.
jmarshall-com commented on issue #1881:
URL: https://github.com/apache/cordova-android/issues/1881#issuecomment-3916816031
Ugh, you're right! Sorry about that, I should have known it. Thanks for all the help.
--
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: issues-unsubscribe@cordova.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [I] WebSocket not opening with version 14.0.1, with simple test case [cordova-android]
Posted by "breautek (via GitHub)" <gi...@apache.org>.
breautek commented on issue #1881:
URL: https://github.com/apache/cordova-android/issues/1881#issuecomment-3916755328
<img width="962" height="151" alt="Image" src="https://github.com/user-attachments/assets/19a67d28-ef0b-439b-b4f8-278d75a01aaf" />
It's because you had a syntax error in your CSP, it's suppose to be `connect-src ...;` not `connect-src: ...;`
Correcting that shows that it's working.
<img width="430" height="888" alt="Image" src="https://github.com/user-attachments/assets/656d3f19-4885-48a6-a33f-df3abfa3d4b5" />
--
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: issues-unsubscribe@cordova.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [I] WebSocket not opening with version 14.0.1, with simple test case [cordova-android]
Posted by "breautek (via GitHub)" <gi...@apache.org>.
breautek closed issue #1881: WebSocket not opening with version 14.0.1, with simple test case
URL: https://github.com/apache/cordova-android/issues/1881
--
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: issues-unsubscribe@cordova.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [I] WebSocket not opening with version 14.0.1, with simple test case [cordova-android]
Posted by "GitToTheHub (via GitHub)" <gi...@apache.org>.
GitToTheHub commented on issue #1881:
URL: https://github.com/apache/cordova-android/issues/1881#issuecomment-3914474495
Hi, this is not an issue because of cordova-android. Use `connect-src 'self' https: wss:;` as CSP derictive. I tested the WebSocket connection and it worked. Here is an example:
```js
ws.onopen = () => {
console.log('WebSocket connected:', wsUrl);
alert('WebSocket connected');
ws.send('ping from cordova');
};
ws.onmessage = (event) => {
console.log('WebSocket message:', event.data);
alert('WebSocket message: ' + event.data);
};
ws.onerror = (error) => {
console.log('WebSocket error:', JSON.stringify(error));
alert('WebSocket error: ' + JSON.stringify(error));
};
ws.onclose = (event) => {
console.log('WebSocket closed:', event.code, event.reason);
alert('WebSocket closed: ' + event.code + ' ' + event.reason);
};
```
--
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: issues-unsubscribe@cordova.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [I] WebSocket not opening with version 14.0.1, with simple test case [cordova-android]
Posted by "jmarshall-com (via GitHub)" <gi...@apache.org>.
jmarshall-com commented on issue #1881:
URL: https://github.com/apache/cordova-android/issues/1881#issuecomment-3917505679
For others who might have this problem later:
My test case here was flawed as others pointed out, but my main app still had the problem of WebSockets not connecting. I eventually found that recreating `package-lock.json`, then removing and installing the android platform fixed the problem, i.e.:
```
rm package-lock.json # or rename it
npm i
cordova platform rm android
cordova platform add android
```
I'm not sure what the problem was, but there were residual plugin directories left under `platforms/android/app/src/main/assets/www/plugins` and `platforms/android/platform_www/plugins` even after I had removed the old plugins. Not sure if that was the cause.
Thanks everyone for the help.
--
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: issues-unsubscribe@cordova.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [I] WebSocket not opening with version 14.0.1, with simple test case [cordova-android]
Posted by "jmarshall-com (via GitHub)" <gi...@apache.org>.
jmarshall-com commented on issue #1881:
URL: https://github.com/apache/cordova-android/issues/1881#issuecomment-3916710974
@breautek Thanks. Here's a sample reproduction app at github. It's the same as the sample code above, except now the `connect-src` is set to `'self' https: wss:;` as @GitToTheHub suggested. It gives the same non-working result.
https://github.com/jmarshall-com/cordova-ws-test
I've also tested a WebSocket connection to the same server using the command-line utility `wscat`, e.g. `wscat -c wss://echo.websocket.org`, and it connects correctly. Also, when running my app on iOS it seems to work correctly. I can't think of anything in my environment that could be interfering with WebSockets, and specifically on Android.
--
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: issues-unsubscribe@cordova.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [I] WebSocket not opening with version 14.0.1, with simple test case [cordova-android]
Posted by "GitToTheHub (via GitHub)" <gi...@apache.org>.
GitToTheHub commented on issue #1881:
URL: https://github.com/apache/cordova-android/issues/1881#issuecomment-3917001623
Sorry, I was wrong by suggesting to set `connect-src 'self' https: wss:;`. `connect-src *;` works also.
--
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: issues-unsubscribe@cordova.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [I] WebSocket not opening with version 14.0.1, with simple test case [cordova-android]
Posted by "breautek (via GitHub)" <gi...@apache.org>.
breautek commented on issue #1881:
URL: https://github.com/apache/cordova-android/issues/1881#issuecomment-3914807120
@jmarshall-com if you can include a [sample reproduction](https://github.com/apache/cordova-contribute/blob/master/create-reproduction.md) app, it will likely help us isolate the bug, or at the very least allow us to explain how or why it is working as intended.
Web socket connection erroring itself isn't a bug -- if there is a legitimate network error occurring.
--
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: issues-unsubscribe@cordova.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org