4

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 !

0

3 Answers 3

4

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 "<URL>" --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 <URL> with the address you want, e.g. 127.0.0.1, google.com.

2
  • thanks ! btw, is there a documentation on options for Chrome for Android activities ? Want to explore the possibilities.
    – themoah
    Commented Jul 28, 2015 at 10:56
  • @Firelord Any way to start in incognito mode? I tried: am start -n com.android.chrome/com.google.android.apps.chrome.document.IncognitoDocumentActivity -d http://google.com, but it didn't work..
    – Gokul NC
    Commented Jun 12, 2016 at 14:25
1

You can also use

am start --user 0 -n com.android.chrome/com.google.android.apps.chrome.Main
0

I recently use the follow command

adb shell am start -n com.android.chrome/org.chromium.chrome.browser.ChromeTabbedActivity -d "https://www.google.com"

The activity name can be found from adb shell dumpsys activity recents | grep -i chrome

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .