I'm making a hybrid app working with Ionic React, using solana web3.js module. Everything works fine when I launch web server, and access on computer and mobile (chrome, firefox).
To build on android, I pass a custom function to fetch when i start the connection on Solana to deal with CORS policy natively. But there is also websocket pubsub on web3.js module, that subscribes everytime it checks a transaction (for example requestAirdrop function).
So, the error I get in Android Studio logcat is : Msg: WebSocket connection to 'wss://api.devnet.solana.com/' failed: Error during WebSocket handshake: Unexpected response code: 403
DYORing during many hours, what i ended with is :
- add something to capacitor webview options that will make the connection accepted by the server/validator ?
- change websocket module inside the solana web3.js node module, allowing the pubsub to work natively ?
Second option will be a nightmare, and don't think I have the knowledge to do it well.
If you see other options, don't hesitate!
UPDATE The issue doesn't come from the webview as a connection from the native app to a web server (specifying server.url to that server in capacitor config) works perfectly with websocket. So the issue is part of capacitor hosting on Android.
and here is my config :
ionic react :
"@awesome-cordova-plugins/core": "^5.44.0", "@awesome-cordova-plugins/http": "^5.44.0", "@capacitor/android": "4.0.1", "@capacitor/app": "4.0.1", "@capacitor/core": "4.0.1", "@ionic/cli": "^6.20.1", "@ionic/react": "6.2.1", "@ionic/react-router": "6.2.1", "@solana/web3.js": "1.53.0", "cordova-plugin-advanced-http": "^3.3.1",
and other that I think irrelevant
android :
Android Studio Chipmunk 2021. Patch2 Runtime version : 11.0.12 Emulator: Pixel2 Android 11.0
I work on Debian.
Thanks a lot.