Re #267 - Pass settings for the proxy setup for webdriver (#326)

* Re #267 - Pass HTTP_PROXY as the proxy setup for webdriver
* Update README.md
pull/331/head
dgtlmoon 3 years ago committed by GitHub
parent ee708cc395
commit 8ec17a4c83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -136,24 +136,9 @@ When you enable a `json:` filter, you can even automatically extract and parse e
`json:$.price` would give `23.50`, or you can extract the whole structure `json:$.price` would give `23.50`, or you can extract the whole structure
### Proxy ### Proxy configuration
A proxy for ChangeDetection.io can be configured by setting environment the See the wiki https://github.com/dgtlmoon/changedetection.io/wiki/Proxy-configuration
`HTTP_PROXY`, `HTTPS_PROXY` variables, examples are also in the `docker-compose.yml`
`NO_PROXY` exclude list can be specified by following `"localhost,192.168.0.0/24"`
as `docker run` with `-e`
```
docker run -d --restart always -e HTTPS_PROXY="socks5h://10.10.1.10:1080" -p "127.0.0.1:5000:5000" -v datastore-volume:/datastore --name changedetection.io dgtlmoon/changedetection.io
```
With `docker-compose`, see the `Proxy support example` in <a href="https://github.com/dgtlmoon/changedetection.io/blob/master/docker-compose.yml">docker-compose.yml</a>.
For more information see https://docs.python-requests.org/en/master/user/advanced/#proxies
This proxy support also extends to the notifications https://github.com/caronc/apprise/issues/387#issuecomment-841718867
### RaspberriPi support? ### RaspberriPi support?

@ -3,6 +3,7 @@ import time
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from selenium import webdriver from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.proxy import Proxy as SeleniumProxy
from selenium.common.exceptions import WebDriverException from selenium.common.exceptions import WebDriverException
import urllib3.exceptions import urllib3.exceptions
@ -65,15 +66,34 @@ class html_webdriver(Fetcher):
command_executor = '' command_executor = ''
# Configs for Proxy setup
# In the ENV vars, is prefixed with "webdriver_", so it is for example "webdriver_sslProxy"
selenium_proxy_settings_mappings = ['ftpProxy', 'httpProxy', 'noProxy',
'proxyAutoconfigUrl', 'sslProxy', 'autodetect',
'socksProxy', 'socksUsername', 'socksPassword']
proxy=None
def __init__(self): def __init__(self):
self.command_executor = os.getenv("WEBDRIVER_URL", 'http://browser-chrome:4444/wd/hub') # .strip('"') is going to save someone a lot of time when they accidently wrap the env value
self.command_executor = os.getenv("WEBDRIVER_URL", 'http://browser-chrome:4444/wd/hub').strip('"')
# If any proxy settings are enabled, then we should setup the proxy object
proxy_args = {}
for k in self.selenium_proxy_settings_mappings:
v = os.getenv('webdriver_' + k, False)
if v:
proxy_args[k] = v.strip('"')
if proxy_args:
self.proxy = SeleniumProxy(raw=proxy_args)
def run(self, url, timeout, request_headers): def run(self, url, timeout, request_headers):
# check env for WEBDRIVER_URL # check env for WEBDRIVER_URL
driver = webdriver.Remote( driver = webdriver.Remote(
command_executor=self.command_executor, command_executor=self.command_executor,
desired_capabilities=DesiredCapabilities.CHROME) desired_capabilities=DesiredCapabilities.CHROME,
proxy=self.proxy)
try: try:
driver.get(url) driver.get(url)

@ -106,10 +106,12 @@ class ValidateContentFetcherIsReady(object):
except urllib3.exceptions.MaxRetryError as e: except urllib3.exceptions.MaxRetryError as e:
driver_url = some_object.command_executor driver_url = some_object.command_executor
message = field.gettext('Content fetcher \'%s\' did not respond.' % (field.data)) message = field.gettext('Content fetcher \'%s\' did not respond.' % (field.data))
message += '<br/>'+field.gettext('Be sure that the selenium/webdriver runner is running and accessible via network from this container/host.') message += '<br/>' + field.gettext(
'Be sure that the selenium/webdriver runner is running and accessible via network from this container/host.')
message += '<br/>' + field.gettext('Did you follow the instructions in the wiki?') message += '<br/>' + field.gettext('Did you follow the instructions in the wiki?')
message += '<br/><br/>' + field.gettext('WebDriver Host: %s' % (driver_url)) message += '<br/><br/>' + field.gettext('WebDriver Host: %s' % (driver_url))
message += '<br/><a href="https://github.com/dgtlmoon/changedetection.io/wiki/Fetching-pages-with-WebDriver">Go here for more information</a>' message += '<br/><a href="https://github.com/dgtlmoon/changedetection.io/wiki/Fetching-pages-with-WebDriver">Go here for more information</a>'
message += '<br/>'+field.gettext('Content fetcher did not respond properly, unable to use it.\n %s' % (str(e)))
raise ValidationError(message) raise ValidationError(message)

@ -13,13 +13,23 @@ services:
# - PUID=1000 # - PUID=1000
# - PGID=1000 # - PGID=1000
# # Alternative WebDriver/selenium URL, do not use "'s or 's! #
# Alternative WebDriver/selenium URL, do not use "'s or 's!
# - WEBDRIVER_URL=http://browser-chrome:4444/wd/hub # - WEBDRIVER_URL=http://browser-chrome:4444/wd/hub
# Proxy support example. #
# WebDriver proxy settings webdriver_ftpProxy, webdriver_httpProxy, webdriver_noProxy,
# webdriver_proxyAutoconfigUrl, webdriver_sslProxy, webdriver_autodetect,
# webdriver_socksProxy, webdriver_socksUsername, webdriver_socksPassword
#
# https://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.common.proxy
#
# Plain requsts - proxy support example.
# - HTTP_PROXY=socks5h://10.10.1.10:1080 # - HTTP_PROXY=socks5h://10.10.1.10:1080
# - HTTPS_PROXY=socks5h://10.10.1.10:1080 # - HTTPS_PROXY=socks5h://10.10.1.10:1080
#
# An exclude list (useful for notification URLs above) can be specified by with # An exclude list (useful for notification URLs above) can be specified by with
# - NO_PROXY="localhost,192.168.0.0/24" # - NO_PROXY="localhost,192.168.0.0/24"
#
# Base URL of your changedetection.io install (Added to the notification alert) # Base URL of your changedetection.io install (Added to the notification alert)
# - BASE_URL=https://mysite.com # - BASE_URL=https://mysite.com

Loading…
Cancel
Save