Is there command line alternative to Chrome Remote Debugging ?
Manually, I can open tabs from chrome://inspect/#devices
. As well as I can open Chrome on desktop from CLI - e.g. chrome.exe --incognito --remote-debugging-port=9222
.
But is there option to open tabs on Chrome on Android, which is connected to PC from CLI ? I need such option to semi-automate tests. thanks !
Answer
Note: You would need root access to run any command mentioned below for Android 4.2.1.
Contrary to traditional desktop OS, apps in Android are called upon using their component, an Activity. While developers can call the activities using the programming, the end-users are left with command-line to do the calling.
Android has an Activity Manager am
to manage the activities, and among other things it can do, the most basic thing it does is to call an activity of an app.
Before we proceed, setup ADB on PC if you haven't since we're going to rely on it. Also make sure that the device is getting detected in PC and by ADB.
The Chrome for Android app's activity responsible for managing tabs is com.google.android.apps.chrome.ChromeTabbedActivity
. You can find this activity listed in the said app's AndroidManifest.xml
(inside the APK). As for how I came to know about it, I simply launched Chrome, opened a tab, and looked upon the most recent activity using the command:
adb shell dumpsys activity recents
Replace recents
with activities
for Android 4.2.1.
The real question is:
[Is] there [an] option to open tabs [in] Chrome on Android?
(Obsolete) Enter the following command to do that:
adb shell am start -n com.android.chrome/com.google.android.apps.chrome.ChromeTabbedActivity -d "" --activity-clear-task
(Tested on Sept 21, 2015) It seems that Chrome has changed the name of the activity responsible for tabs. The new command is:
adb shell am start -n com.android.chrome/org.chromium.chrome.browser.ChromeTabbedActivity -d "about:newtab" --activity-clear-task
See step 3. in this answer to know the details of the command, if you're interested.
Replace
with the address you want, e.g. 127.0.0.1
, google.com
.
No comments:
Post a Comment