Hey folks, I’m stuck with a tricky problem. I’m trying to automate some tasks on a website using Android. Right now, I’m using WebView with a JS-Java interface, which works but it’s not ideal. I have to make the WebView fullscreen and invisible in a service to run it in the background.
The main issue is that the site uses websockets for requests, so I can’t just use simple GET/POST in Java. The website’s JavaScript is heavily obfuscated, making it hard to figure out the websocket API (Chrome debugger only shows ‘Binary OPCode 2’ in Frames).
I’m wondering if there’s a better way to do this on Android - maybe some kind of headless browser that supports websockets? Any ideas would be super helpful. Thanks!
Have you considered using a library like OkHttp for handling WebSocket connections in Android? It’s a robust solution that doesn’t require a WebView. You can establish a WebSocket connection, send messages, and receive responses directly in Java code.
For the obfuscated JavaScript issue, you might need to reverse engineer the site’s API. Tools like Fiddler or Charles Proxy can help intercept and analyze the WebSocket traffic, giving you insights into the message structure and protocol.
If you absolutely need to execute JavaScript, you could look into using a headless browser like Selenium with ChromeDriver in Android. It’s more complex to set up, but it allows for background execution without a visible UI.
Remember to respect the website’s terms of service and any legal considerations when automating interactions.
I’ve been down this road before, and it’s definitely a tricky one. Have you looked into using JSoup? It’s a Java library that can parse HTML and manipulate DOM elements without needing a WebView. I’ve used it for similar tasks, and while it doesn’t handle WebSockets out of the box, you can combine it with a WebSocket client library like Nv-WebSocket-Client.
For the obfuscated JS, I’d recommend using a network sniffer like Wireshark to capture the WebSocket traffic. It helped me decode the message structure when I was working on a similar project. Once you understand the protocol, you can replicate it in your Java code.
If all else fails, you might want to consider running a headless browser on a server and controlling it remotely from your Android app. It’s not ideal, but it could solve both the WebSocket and background execution issues in one go. Just be careful with the website’s ToS – some explicitly prohibit this kind of automation.
yo, try lookin into java-websocket library. it lets u handle websockets without webview. for the obfuscated js, maybe use a proxy like mitmproxy to check the traffic. if u need to run js, phantomjs might work, but its tricky on android. just watch out for tos violations n stuff