我想要找到一个能够使用特定的x和y坐标打开Google Chrome的shell命令(这样我可以设置窗口打开时的位置)。是否可能使用命令行参数来实现这一点?
为了实现这个目标,我需要修改以下命令:
google-chrome http://www.google.com/
我想要找到一个能够使用特定的x和y坐标打开Google Chrome的shell命令(这样我可以设置窗口打开时的位置)。是否可能使用命令行参数来实现这一点?
为了实现这个目标,我需要修改以下命令:
google-chrome http://www.google.com/
当你使用Google 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>"
优点:
缺点:
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" \
--user-data-dir
标志。 - Frederik Krautwald--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/"
对我来说不幸的是,将它作为一个新实例意味着它不会从其他实例中传递会话/cookie等信息,因此我必须正常打开它(只使用--app
参数),然后在我打开的页面中使用JavaScript做以下操作:
window.moveTo(580,240);
window.resizeTo(800,600);
我猜,如果你要打开别人拥有的网页,你可以打开自己的网页,该网页包含上述js代码,并导航到他们的网页。
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 "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>"
提供一种不错的方法来完成这个任务。
注意:这个方法在火狐浏览器中同样有效。
onclick
替换为 onfocus
,则在 Chrome 中只需按 <tab>
键即可正常工作,但在 Firefox 中不行... 可能是安全问题!? - F. Hauri - Give Up GitHub在我最新的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位)中有效。
这对我有用。
"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"
user-data-dir
。为了运行多个独立的Chrome浏览器进程,每个进程都需要自己的配置文件。您可以在每次运行浏览器实例时指定--user-data-dir="path/to/profile/#"(将#更改为不同的数字或使用完全不同的路径)。注意 - 路径不必存在,它只需要是合法的(并且Chrome应该有权限在不存在的情况下创建它)。 Chrome会创建尚不存在的配置文件路径
.. 在这个链接中找到了相关信息。
window-position=3000,0
可以帮助将窗口位置移动到另一个显示器上。user-data-dir
中的 #
为不同的数字。