chromium自定义启动参数 和 启用远程调试

下载二进制chromium 请看这里

命令行启动chromium

set -exu

__DIR__=$(cd "$(dirname "$0")";pwd)
cd ${__DIR__}

uuid=$(cat /proc/sys/kernel/random/uuid)
dir="/tmp/${uuid}"
if [ ! -d $dir ] ;then
  mkdir $dir
fi
export GOOGLE_API_KEY="no"
export GOOGLE_DEFAULT_CLIENT_ID="no"
export GOOGLE_DEFAULT_CLIENT_SECRET="no"

kernel_name=$(uname -s)
echo "$kernel_name"

## 下载chromium 请看这里 https://www.cnblogs.com/jingjingxyk/p/16577937.html


# mac
chromium="${__DIR__}/chrome-mac/Chromium.app/Contents/MacOS/Chromium"
# windows
chromium='chrome-win\\chrome.exe'

# linux 
chromium="${__DIR__}/chrome-linux/chrome"


# 加载浏览器扩展
git clone -b master --depth=1 https://github.com/justjavac/ReplaceGoogleCDN.git
git clone -b main --depth=1 https://github.com/jingjingxyk/extension-v3-test.git


extensions=`${__DIR__}/extension-v3-test,${__DIR__}/ReplaceGoogleCDN/extension`



${__DIR__}/Default/chrome \
--user-data-dir=$dir \
--show-app-list \
--start-maximized \
--enable-remote-extensions  \
--enable-extensions \
--remote-debugging-port=9221 \
--enable-logging=stderr --v=1 \
--load-extension="$extensions" \
--disable-encryption --disable-machine-id \
about:blank


# 远程调试
# --remote-debugging-port=9221
# 命令行显示浏览器请求日志
# --enable-logging=stderr --v=1 
# 启用调试渲染器可访问性功能  chrome://accessibility 
# --force-renderer-accessibility
# 允许本地文件加载
# --args --allow-file-access-from-files 允许本地文件加载
# 添加HEVC 解码能力
# --args --enable-features=PlatformHEVCDecoderSupport

## 请求不携带cookie问题
# --args --disable-features=SameSiteByDefaultCookies,CookiesWithoutSameSiteMustBeSecure
# 关闭网络安全
# --disable-web-security

# 浏览器自动打开调试窗口
# --auto-open-devtools-for-tabs 
# 浏览器使用http代理
# --proxy-server="http=127.0.0.1:8016;https=127.0.0.1:8016"
# 浏览器使用socks5代理
# --proxy-server="socks5://127.0.0.1:1080" --host-resolver-rules="MAP * ~NOTFOUND,EXCLUDE 127.0.0.1"
# 浏览器使用pac代理 
# --proxy-pac-url="http://localhost:8000/proxy.pac"

# 全屏
# --start-fullscreen 

# chromium 帐号密码 存放所在文件: ”Default/Login Data“

# 获得https 密钥
# export SSLKEYLOGFILE=${__DIR__}/SSL_KEY_LOG_FILE

chromium 远程调试默认允许localhost 域,我们借助 socat 跳出localhost域名限制


socat -d -d TCP4-LISTEN:9222,reuseaddr,reuseport,fork,retry=3 TCP4:localhost:9221


curl http://localhost:9222/json/protocol
curl  http://192.168.3.103:9222/json/new?https://stackoverflow.com/tags/socat/hot?filter=all


chromium 常用查询命令

浏览器地址栏输入如下命令

查看内部支持的 URL 列表
chrome://chrome-urls
            
# 查询网络状况
chrome://net-internals/#hsts

chrome://credits
展示所有第三方软件许可证(开放源代码软件)

chrome://dns
展示DNS状态, 一般用来监控排查排查网络问题

chrome://extensions
展示所有安装的扩展程序

chrome://flags
传说中的里选项, 打开以后会看到警告性的”核辐射”标志,
除非遇到问题(比如GPU什么的), 这里的选项还是不要随便碰.


展示GPU相关信息, 主要是排查问题和调试用
chrome://gpu-internals
      

备注:下载chromium 请看这里

不使用headless模式 在容器中运行chromium

  1. 不使用headless模式 在容器中运行chromium

参考文档

  1. chromium socks 设置
  2. 8K HDR!|为 Chromium 实现 HEVC 硬解 - 原理/实测指南
  3. 下载浏览器扩展商店里的扩展,并保存crx文件
  4. 下载最新二进制 chromium
  5. 快速下载chromium源码
  6. Chrome浏览器启动参数大全(命令行参数)
  7. Chrome浏览器启动命令行参数
  8. Chromium with command-line switches
  9. Chromium with command-line switches examples
  10. Chrome Platform Status
  11. chromiumdash
  12. firefox 命令行参数
  13. 解密https流量
  14. 容器中运行chromium

容器中运行 chromium 关键点

使用 xvfb 实现

关键点https://github.com/jingjingxyk/chromium-run-in-container/blob/main/tools/startup-xvfb-chromium.sh


xvfb-run  -s "-terminate -screen 0 1920x1080x24"  ${__DIR__}/Default/chrome 

问题(2023-04-16)

暂不知道如何屏蔽 chrome://intro/
2022-08-10 新添加的功能 code change

posted @ 2022-08-11 21:35  jingjingxyk  阅读(1670)  评论(0编辑  收藏  举报