使用特定窗口坐标从命令行启动Google Chrome

1zmg4dgp  于 2023-04-03  发布在  Go
关注(0)|答案(6)|浏览(268)

我试图找到一个shell命令,将打开谷歌浏览器与特定的x和y坐标(这样我就可以设置的位置,当它打开窗口)。是否可以做到这一点使用命令行参数?
我需要修改以下命令来实现这一点:
google-chrome http://www.google.com/

nsc4cvqm

nsc4cvqm1#

当你使用谷歌的Chrome浏览器时,有一个更短的方法:

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" 
     --profile-directory="Default"
     --app="data:text/html,<html><body><script>window.moveTo(580,240);window.resizeTo(800,600);window.location='http://www.test.de';</script></body></html>"

优点:

  • 自动打开窗口
  • 避免弹出窗口阻止程序
  • 在不同的显示器上打开多个窗口(多显示器设置,需要两个或更多Chrome配置文件)

缺点:

  • 似乎只能在“应用程序”模式下工作
  • 未使用其他浏览器进行测试
8aqjt8rx

8aqjt8rx2#

http://peter.sh/experiments/chromium-command-line-switches/说--window-position=x,y就是你要找的。
几年后更新,包括我几年前写的一个小shell脚本(但在回答这个问题后),它提供了一个如何启动chrome的例子,自定义窗口大小/位置,并有能力通过名称创建“假”用户数据目录。
它可能仍然工作,也可能不工作,并且设置了一些危险的选项,但是你明白了..不要逐字逐句地使用它,一些标志可能已经被重命名或完全删除..(就像socks代理命令一样)

#!/bin/bash -x

FAKEUSER="${1:-fake-chrome-user}"
CHROMEROOT=$HOME/.chromeroot/

mkdir -p ${CHROMEROOT}

export PROFILE="${CHROMEROOT}/${FAKEUSER}-chromium-profile"
export DISK_CACHEDIR="${CHROMEROOT}/${FAKEUSER}-chromium-profile-cache"
export DISK_CACHESIZE=4096
export MEDIA_CACHESIZE=4096

PARANOID_OPTIONS="\
        --no-displaying-insecure-content \
        --no-referrers \
        --disable-zero-suggest \
        --disable-sync  \
        --cipher-suite-blacklist=0x0004,0x0005,0xc011,0xc007 \
        --enable-sandbox-logging >/dev/null 2>&1
        "

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
        --remember-cert-error-decisions \
        --ignore-certificate-errors \
        --ignore-urlfetcher-cert-requests \
        --allow-running-insecure-content \
        --window-position=2400,400 \
        --window-size=1500,1000 \
        --no-pings \
        --user-data-dir=${PROFILE} \
        --disk-cache-dir=${DISK_CACHEDIR} \
        --disk-cache-size=${DISK_CACHESIZE} \
        --media-cache-size=${MEDIA_CACHESIZE} \
        2>&1

#--proxy-server="socks4://localhost:30604" \
#--host-resolver-rules="MAP * 0.0.0.0 , EXCLUDE localhost" \
cu6pst1q

cu6pst1q3#

基于@synthesizerpatel的答案,--window-position无法独立工作。
您需要使用--user-data-dir--chrome-frame将其作为自己的新示例启动,如下所示:

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"  --user-data-dir=XXXXXXXXXX --window-size=800,600 --window-position=580,240 --app="http://www.google.com/"
or
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --chrome-frame --window-size=800,600 --window-position=580,240 --app="http://www.google.com/"

不幸的是,将它作为一个新示例意味着它不会从其他示例中携带session/cookie/etc信息,所以我不得不正常打开它(只有--app参数),然后在我打开的页面中使用javascript:

window.moveTo(580,240);
window.resizeTo(800,600);

我想如果你打开的是别人的网页,你可以打开你自己的网页,上面有js,然后导航到他们的网页。

5kgi1eie

5kgi1eie4#

我用过这个:

google-chrome "data:text/html;charset=ISO-8859-1,<html>
    <head></head><body><script language=\"javascript\">
        window.open('http://perso.f-hauri.ch/~felix/svg/dustin_w_Clock_autonom.svg',
             'clock','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,'
             +'resizable=1,width=600,height=600,top=100,left=120');</script>"

但是 google-chrome 阻止 * 弹出窗口 *,所以:

google-chrome "data:text/html;charset=ISO-8859-1,<html><head></head><body>
    <button onclick=\"javascript:window.open(
        'http://perso.f-hauri.ch/~felix/svg/dustin_w_Clock_autonom.svg',
        'clock','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,'
        +'resizable=1,width=600,height=600,top=100,left=120');\"> clock </button>"

给予一个很好的方式来做到这一点。

**注:**这也适用于Firefox。

2j4z5cfb

2j4z5cfb5#

使用我最新版本的Chrome -我只需要以下内容。每次我关闭应用程序,它都会记住我的窗口大小和位置。

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --chrome-frame --app=https://mightytext.net/web8/?exp=1

我在版本48.0.2564.48 beta-m(64位)和版本48.0.2564.48 beta-m(64位)中使用了这个方法

brjng4g3

brjng4g36#

这对我很有效。

"C:\Program Files\Google\Chrome\Application\chrome.exe" --user-data-dir="C:\Users\hello\gtemp\123" --window-size=100,1000 --window-position=3000,0 "https://www.openchromeonadifferentwindow.com"

1.需要user-data-dir
为了运行多个单独的Chrome浏览器进程,每个进程都需要自己的配置文件。您可以指定--user-data-dir=“path/to/profile/#”(将#更改为不同的数字或使用完全不同的路径)。注意-路径不一定存在,它只需要是法律的的(如果它不存在,Chrome应该有权限创建它)。Chrome将创建尚不存在的配置文件路径
..在这个link上发现它很有帮助。

  1. window-position=3000,0帮助将窗口位置移动到另一个监视器
    1.如果要打开其他设置不同的示例,需要将user-data-dir#更改为其他数字

相关问题