Run google-chrome with flags on Android

微笑、不失礼 提交于 2019-12-18 01:16:14

问题


There are command line flags (or "switches") that Chromium (and Chrome) accept in order to enable particular features or modify otherwise default functionality.

Chromium Command Line Switches

Run Chromium with flags

Tried Chrome 41.0.xx and Chromium 43.0.xxx shell with:

# echo "chrome <flags>" > /data/local/tmp/android-webview-command-line
# echo "chrome <flags>" > /data/local/tmp/content-shell-command-line

Any idea how to run chrome with flags on Android or directly add these into default profile.

Want to add --sync-url flag to use my sync server instead of google sync servers. chrome://flags only enable/disable flags but wont let you add new flag.


回答1:


New method added in Chrome 661 that works for a production build on unrooted devices.

  1. Using adb, write the flags to /data/local/tmp/chrome-command-line.

    For example:

    ~$ adb shell 'echo --unsafely-treat-insecure-origin-as-secure=http://a.test > /data/local/tmp/chrome-command-line'
    
  2. In chrome://flags, turn on enable-command-line-on-non-rooted-devices.

  3. Force stop Chrome (the relaunch now button will not trigger the reading of the flags file, even though the danger snackbar will disagree).

Verify in chrome://version that this worked.

https://www.chromium.org/developers/how-tos/run-chromium-with-flags#TOC-Android




回答2:


What you're doing is correct, but seems like you're writing the switches to the wrong file for Chrome (and note that the file that you write the switches to may vary based on the OS version [or maybe phone?] ).

I tried this on two different phones, and had to write to two different files! Hopefully one of them will work for you:

Phone 1: Nexus 6 with Android 6.0.1

Simply do the following in adb shell:

echo "chrome --sync-url" > /data/local/tmp/chrome-command-line'

Phone 2: MotoG with Android 4.4.4

This is a bit trickier. It turned out that Chrome actually reads the switches from /data/local/chrome-command-line (not in the tmp subdirectory!). Now the issue is that on an unrooted phone you won't have permission to write to this file! So I had to root my phone* and use su to write to the file:

  1. adb shell
  2. su
  3. echo "chrome --sync-url" > /data/local/chrome-command-line

*Rooting an Android phone is actually very easy and takes only a few minutes. There are a number of one click apps for rooting your phone (e.g. KingoRoot). For the case of MotoG, I had to do a few more steps to root, following this)




回答3:


You need chromium debug build in order to use these switches.




回答4:


I needed insecure origin flag for testing of service workers on mobile device. However, for some reason these flags did not work on mobile chrome. Behaviour similar to insecure origin flag can be achieved by port forwarding.

You can find further info in my original answer here: https://stackoverflow.com/a/56146180/5048121

This does not apply exclusively on service workers, if you need https behavior on mobile device, you can combine it for example with allow-insecure-localhost flag or use self-signed certificate for localhost on server and get rid of cert errors on mobile chrome.



来源:https://stackoverflow.com/questions/29280796/run-google-chrome-with-flags-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!