If you enjoy using Chrome, which is the default browser for newer versions of Android, you can use Chrome remote debugging .
Once you have enabled this on your device (enable usb debugging + web debugging), you can connect by doing:
adb forward tcp:9222 localabstract:chrome_devtools_remote
If you click localhost: 9222 from your browser, you will see Chrome tools for each of your tabs. From here, you can do everything you can usually do in the chrome inspector on your desktop, including running JavaScript from the console.
If this is not automated enough, you can write an application that uses WebView, configure it to handle the intent in which you produce arbitrary JavaScript, and use webview.loadUrl(js) to execute it.
source share