bash 从具有特定窗口坐标的命令行启动 Google Chrome
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13436855/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Launch Google Chrome from the command line with specific window coordinates
提问by Anderson Green
I'm trying to find a shell command that will open Google Chrome with specific x and y coordinates (so that I can set the position of the window when it opens.) Is it possible to do this using command line-arguments?
我正在尝试找到一个 shell 命令,该命令将使用特定的 x 和 y 坐标打开谷歌浏览器(以便我可以在打开时设置窗口的位置。)是否可以使用命令行参数来执行此操作?
I need to modify the following command in order to achieve this:
我需要修改以下命令才能实现此目的:
google-chrome http://www.google.com/
google-chrome http://www.google.com/
采纳答案by synthesizerpatel
http://peter.sh/experiments/chromium-command-line-switches/says --window-position=x,y is what you're looking for.
http://peter.sh/experiments/chromium-command-line-switches/说 --window-position=x,y 就是你要找的。
Updating this years later to include a small shell script I wrote years ago (but after answering this question) that provides an example of how to start chrome with custom window sizes/position and has the ability to create 'fake' user data directories by name.
几年后更新以包含我几年前写的一个小 shell 脚本(但在回答这个问题之后),它提供了一个示例,说明如何使用自定义窗口大小/位置启动 chrome,并能够按名称创建“假”用户数据目录.
It may or may not still work, and has some dangerous options set, but you get the idea.. Do not use this verbatim, some of the flags may have been renamed or been removed entirely.. (like the socks proxy commands did)
它可能仍然有效,也可能不再有效,并且设置了一些危险的选项,但你明白了.. 不要逐字使用,一些标志可能已被重命名或完全删除..(就像袜子代理命令一样)
#!/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" \
回答by nitram509
When you're using Google's Chrome, there is a shorter way:
当您使用 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>"
Pro:
亲:
- Automatically opens the window
- Avoids the popup-blocker
- Opens multiple windows on different monitors (multi monitor setup, requires two or more Chrome profiles)
- 自动打开窗口
- 避免弹出窗口阻止程序
- 在不同的显示器上打开多个窗口(多显示器设置,需要两个或多个 Chrome 配置文件)
Con:
骗局:
- Only seems to work in "app" Mode
- Not tested with other browsers
- 似乎只能在“应用程序”模式下工作
- 未在其他浏览器上测试
回答by Redzarf
To build on @synthesizerpatel's answer, --window-position
won't work on it's own.
要以@synthesizerpatel 的答案为基础,--window-position
它自己将无法工作。
You'll need to launch it as it's own new instance using --user-data-dir
or --chrome-frame
like:
您需要使用--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/"
Unfortunately for me, having it as a new instance means it doesn't carry over the session/cookie/etc info from other instances, so I've had to open it normally (with only the --app
parameter), then have javascript in the page I open do:
对我来说不幸的是,将它作为一个新实例意味着它不会从其他实例继承会话/cookie/etc 信息,所以我不得不正常打开它(只有--app
参数),然后在页面中有 javascript我打开做:
window.moveTo(580,240);
window.resizeTo(800,600);
I guess if you were opening a webpage owned by someone else, you could open your own webpage that has the above js, and then navigates to their webpage.
我想如果你打开一个别人拥有的网页,你可以打开自己的网页,上面有上面的js,然后导航到他们的网页。
回答by F. Hauri
I've used this:
我用过这个:
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>"
but google-chromeblock popup windows, so this:
但是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>"
give a nice way to do this.
给出一个很好的方法来做到这一点。
Nota:This work as well with firefox too.
注意:这也适用于 Firefox。
回答by BickiBoy
With my latest version of Chrome - I only needed the following. Everytime I closed the app, it remembered my window size and position.
使用我最新版本的 Chrome - 我只需要以下内容。每次我关闭应用程序时,它都会记住我的窗口大小和位置。
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --chrome-frame --app=https://mightytext.net/web8/?exp=1
This worked for me in Version 48.0.2564.48 beta-m (64-bit) and Version 48.0.2564.48 beta-m (64-bit)
这在版本 48.0.2564.48 beta-m(64 位)和版本 48.0.2564.48 beta-m(64 位)中对我有用