헤드리스 모드에서 Chrome을 시작하는 방법은 없나요?
http://peter.sh/experiments/chromium-command-line-switches/#chrome-frame 에서 스위치 목록을 신중하게 수정 했는데 숨겨진 백그라운드 프로세스에서 Chrome을 실행할 수있는 항목을 찾을 수 없었습니다.
내가 할 수 있었던 가장 가까운 것은 --keep-alive-for-test+ 사용자 정의 패키지 앱이지만, (보고하는 방식) "no window-ChromeHidden"때문에 앱이 전달 된 코드를 실행하지 못했습니다.
TL; DR
google-chrome --headless --remote-debugging-port=9222 http://example.com
--disable-gpu일시적으로 필요합니다 .
튜토리얼 :
https://developers.google.com/web/updates/2017/04/headless-chrome
진행중인 작업이 있습니다. https://code.google.com/p/chromium/issues/detail?id=546953
주요 결과물은 다음과 같습니다.
- 헤드리스 애플리케이션이 연결할 수있는 라이브러리입니다.
- 헤드리스 API 사용을 보여주는 샘플 애플리케이션입니다.
따라서 디스플레이에 연결하지 않고 콘솔에서 실행되는 간단한 응용 프로그램을 만들 수 있습니다.
업데이트 Apr 18 '16 : 작업이 주로 이루어집니다. 이제 공개 포럼이 있습니다.
https://groups.google.com/a/chromium.org/forum/#!forum/headless-dev
문서화 진행 중 :
https://chromium.googlesource.com/chromium/src/+/master/headless/README.md
업데이트 Sep 20 '16 : chrome이 결국 "--headless"매개 변수를 얻게 될 것 같습니다 : https://bugs.chromium.org/p/chromium/issues/detail?id=612904
BlinkOn 6에 대한 프레젠테이션 이있었습니다 (2016 년 6 월 16 일 / 17 일)
'16 년 11 월 29 일 업데이트 :--headless 플래그 용 디자인 문서 : https://docs.google.com/document/d/1aIJUzQr3eougZQp90bp4mqGr5gY6hdUice8UPa-Ys90/edit#heading=h.qxqfzv2lj12s
업데이트 Dec 13 '16 : --headless Canary 빌드에서 곧 플래그를 사용할 수있을 것으로 예상됩니다.
업데이트 Mar 12 '17 : Chrome 57에 --headless플래그가 작동합니다. Selenium 및 기타 도구가 따라 잡을 때까지 기다립니다. 사용자 가이드 : https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md
이 사람은 Xvfb (X 가상 프레임 버퍼)를 사용하여 Chrome이 창을 표시한다고 생각하도록 속임으로써 Chrome을 헤드리스로 실행했습니다.
http://e-method.blogspot.fr/2010/11/google-chrome-with-xvfb-headless-server.html
Linux를 사용하는 경우 시도해 볼 수 있습니다.
따라서 기본적으로 다음을 통해 X 가상 프레임 버퍼와 Google 크롬을 설치해야합니다.
root@localhost: ~# apt-get install xvfb imagemagick
root@localhost: ~# apt-get install google-chrome
그런 다음 디스플레이에서 브라우저를 실행합니다.
root@localhost: ~# xvfb-run --server-args='-screen 0, 1024x768x24' \
google-chrome -start-maximized http://www.example.com \
> & /dev/null &
root@localhost: ~# DISPLAY=:99 import -window root myimage.png
또는 헤드리스 WebKit 구현 인 PhantomJS 프로젝트를 볼 수 있습니다 .
Linux VM을 설정하고 xvfb를 사용할 수 있습니다.
데비안 / 우분투에 설치 :
sudo aptitude install xvfb
헤드리스 Chrome을 시작하고 http://example.com을 방문하십시오 .
xvfb-run --server-args='-screen 0, 1024x768x16' google-chrome
-start-maximized http://example.com > /dev/null &
자식 하위 프로세스로 시작하면 헤드리스 모드에서 시작됩니다. 그 외에도 :
- nircmd.exe는
win hidePID를 기반으로 크롬에서 수행 할 수 있습니다. - Autohotkey_L은 작업 표시 줄 버튼없이 숨겨진 Chrome을 시작할 수도 있습니다.
The Chromium Embedded Framework project seems like it might fit your usecase. I don't have personal experience with the project, but I've heard good things, and it has a solid API that you should be able to exploit for your purposes.
I don't have enough reputation to comment yet, but want to let you guys know that the chrome headless mode which Vanuan mentions actually works with Selenium webdriver.
In Java you can pass the flag to chrome through chromeDriver with the following code:
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
ChromeDriver chromeDriver = new ChromeDriver(options);
I've recently found this article which mentions several commandline options that seem to do it. Using these keywords I googled out this piece of code which seem to confirm that these options exist.
// Does not automatically open a browser window on startup (used when
// launching Chrome for the purpose of hosting background apps).
const char kNoStartupWindow[] = "no-startup-window";
// Causes Chrome to launch without opening any windows by default. Useful if
// one wishes to use Chrome as an ash server.
const char kSilentLaunch[] = "silent-launch";
I managed to successfuly run Chrome with --no-startup-window and indeed it launched without any windows. It looked like it launched properly, it spawned all typical children, but the website I tried to make it load inside didn't seem to be actually visited. It maybe possible that this headless mode is only for running apps and not for visiting sites headless*), but it looks very promising as the normal worker tree is set up, just no windows.
The second option --silent-launch made chrome process very silent. I didn't notice any children spawned and the process exited promptly. I doubt it'll be usable for this case.
After I failed my attempts with these options, I focused on less sophisticated ways. On the bottom of the list there are two options:
// Specify the initial window position: --window-position=x,y
const char kWindowPosition[] = "window-position";
// Specify the initial window size: --window-size=w,h
const char kWindowSize[] = "window-size";
I ran Chrome with options to move it completely out of the working area:
--window-size=800,600 --window-position=-800,0
and as dirty as it feels, sure it's no true headless, but still the window is out of my sight, and everything done just with chrome's startup options, without external tools sending low-level window-hide messages.
*) yes, I know try to do weird things. Essentially I tried to get rid of Chrome window that's kept by Karma during tests. I know I can switch to PhantomJS, but I specifically needed to run them in Chrome, and the window popping out was.. eh.. disturbing in the long run.
It is currently under development, you can read more information about it from here: https://chromium.googlesource.com/chromium/src/+/master/headless/README.md
Headless Chromium is a library for running Chromium in a headless/server environment. Expected use cases include loading web pages, extracting metadata (e.g., the DOM) and generating bitmaps from page contents -- using all the modern web platform features provided by Chromium and Blink.
It currently works on Linux, there is a nice presentation.
I was also able to make chrome headless work with NightwatchJS. Here is the config that let me use it:
"chromeHeadless": {
"desiredCapabilities": {
"browserName": "chrome",
"chromeOptions": {
"args": ["--headless"],
"binary": "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary"
}
}
}
Chrome 59 has the ability to create instance as headless. Find the below tutorial https://www.automation99.com/2017/07/how-to-use-chrome-headless-using.html?m=1
ReferenceURL : https://stackoverflow.com/questions/9210765/any-way-to-start-google-chrome-in-headless-mode
'Program Club' 카테고리의 다른 글
| C ++에서 "this"키워드 사용 (0) | 2020.12.15 |
|---|---|
| Highcharts 차트 최대 yAxis 값을 설정하는 방법 (0) | 2020.12.15 |
| Golang에서 os / exec로 시작된 프로세스 종료 (0) | 2020.12.15 |
| 여러 개의 다른 InputStream을 하나의 InputStream으로 연결하는 방법 (0) | 2020.12.15 |
| C-% x 형식 지정자 (0) | 2020.12.15 |