mirror of
https://github.com/vimagick/dockerfiles.git
synced 2024-12-23 01:39:27 +02:00
update browserless
This commit is contained in:
parent
bfb26b8b96
commit
37f07d09af
@ -8,19 +8,21 @@ to.
|
||||
## docker-compose.yml
|
||||
|
||||
```yaml
|
||||
browserless:
|
||||
image: browserless/chrome:1-chrome-stable
|
||||
ports:
|
||||
- "3000:3000"
|
||||
environment:
|
||||
- DEBUG=browserless/chrome
|
||||
- MAX_CONCURRENT_SESSIONS=10
|
||||
- CONNECTION_TIMEOUT=600000
|
||||
- MAX_QUEUE_LENGTH=10
|
||||
- ENABLE_CORS=true
|
||||
- CHROME_REFRESH_TIME=3600000
|
||||
shm_size: 2gb
|
||||
restart: always
|
||||
version: '3.8'
|
||||
services:
|
||||
browserless:
|
||||
image: browserless/chrome:1-chrome-stable
|
||||
ports:
|
||||
- "3000:3000"
|
||||
environment:
|
||||
- DEBUG=browserless/chrome
|
||||
- MAX_CONCURRENT_SESSIONS=100
|
||||
- CONNECTION_TIMEOUT=300000
|
||||
- MAX_QUEUE_LENGTH=100
|
||||
- ENABLE_CORS=true
|
||||
- ENABLE_DEBUG_VIEWER=true
|
||||
- EXIT_ON_HEALTH_FAILURE=true
|
||||
restart: unless-stopped
|
||||
```
|
||||
|
||||
## screenshot.js
|
||||
@ -28,30 +30,67 @@ browserless:
|
||||
```javascript
|
||||
'use strict';
|
||||
|
||||
const puppeteer = require('puppeteer');
|
||||
const puppeteer = require('puppeteer-core');
|
||||
|
||||
(async() => {
|
||||
const browser = await puppeteer.connect({browserWSEndpoint: 'ws://localhost:3000'});
|
||||
const page = await browser.newPage();
|
||||
await page.setViewport({width: 1280, height: 720});
|
||||
await page.goto('https://www.google.com/', {waitUntil: 'networkidle2'});
|
||||
await page.waitForSelector('img[alt="Google"]');
|
||||
await page.screenshot({path: 'google.png', fullPage: true});
|
||||
await browser.close();
|
||||
})();
|
||||
```
|
||||
|
||||
## screenshot.py
|
||||
|
||||
```python
|
||||
#!/usr/bin/env python
|
||||
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
|
||||
options = webdriver.ChromeOptions()
|
||||
options.add_argument("--window-size=1024,768")
|
||||
options.add_argument('--headless')
|
||||
options.add_argument('--no-sandbox')
|
||||
|
||||
driver = webdriver.Remote(
|
||||
command_executor='http://localhost:3000/webdriver',
|
||||
options=options
|
||||
)
|
||||
|
||||
driver.get('https://www.google.com/')
|
||||
|
||||
WebDriverWait(driver, 10).until(
|
||||
EC.presence_of_element_located((By.CSS_SELECTOR, 'img[alt="Google"]'))
|
||||
)
|
||||
|
||||
driver.save_screenshot('google.png')
|
||||
driver.close()
|
||||
driver.quit()
|
||||
```
|
||||
|
||||
## Up and Running
|
||||
|
||||
```bash
|
||||
$ docker-compose up -d
|
||||
$ PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true npm install puppeteer
|
||||
|
||||
$ npm install puppeteer-core
|
||||
$ node screenshot.js
|
||||
$ imgcat google.png
|
||||
|
||||
$ pip install selenium
|
||||
$ python screenshot.py
|
||||
$ imgcat google.png
|
||||
|
||||
$ http http://127.0.0.1:3000/screenshot \
|
||||
url=https://www.youtube.com \
|
||||
options:='{"fullPage":true}' \
|
||||
gotoOptions:='{"waitUntil":"networkidle2"}' > youtube.png
|
||||
options[fullPage]:=true \
|
||||
gotoOptions[waitUntil]=networkidle2 > youtube.png
|
||||
$ imgcat youtube.png
|
||||
```
|
||||
|
||||
|
@ -1,14 +1,15 @@
|
||||
browserless:
|
||||
image: browserless/chrome:1-chrome-stable
|
||||
ports:
|
||||
- "3000:3000"
|
||||
environment:
|
||||
- DEBUG=browserless/chrome
|
||||
- MAX_CONCURRENT_SESSIONS=10
|
||||
- CONNECTION_TIMEOUT=600000
|
||||
- MAX_QUEUE_LENGTH=10
|
||||
- CHROME_REFRESH_TIME=3600000
|
||||
- ENABLE_CORS=true
|
||||
- EXIT_ON_HEALTH_FAILURE=true
|
||||
shm_size: 2gb
|
||||
restart: always
|
||||
version: '3.8'
|
||||
services:
|
||||
browserless:
|
||||
image: browserless/chrome:1-chrome-stable
|
||||
ports:
|
||||
- "3000:3000"
|
||||
environment:
|
||||
- DEBUG=browserless/chrome
|
||||
- MAX_CONCURRENT_SESSIONS=100
|
||||
- CONNECTION_TIMEOUT=300000
|
||||
- MAX_QUEUE_LENGTH=100
|
||||
- ENABLE_CORS=true
|
||||
- ENABLE_DEBUG_VIEWER=true
|
||||
- EXIT_ON_HEALTH_FAILURE=true
|
||||
restart: unless-stopped
|
||||
|
Loading…
Reference in New Issue
Block a user