Skip to content

Commit

Permalink
Remove unnecessary chrome options & upgrade chrome version
Browse files Browse the repository at this point in the history
  • Loading branch information
wm3ndez committed Aug 11, 2024
1 parent e720190 commit e7f7dfd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ RUN apt-get install -y \
--no-install-recommends

RUN wget --no-verbose -O /tmp/chrome.deb \
https://dl.google.com/linux/deb/pool/main/g/google-chrome-stable/google-chrome-stable_126.0.6478.61-1_amd64.deb \
https://dl.google.com/linux/deb/pool/main/g/google-chrome-stable/google-chrome-stable_127.0.6533.99-1_amd64.deb \
&& apt install -y /tmp/chrome.deb \
&& rm /tmp/chrome.deb

Expand All @@ -42,7 +42,7 @@ RUN apt install unzip \
&& apt clean \
&& rm -rf /var/lib/apt

RUN wget https://storage.googleapis.com/chrome-for-testing-public/126.0.6478.61/linux64/chromedriver-linux64.zip \
RUN wget https://storage.googleapis.com/chrome-for-testing-public/127.0.6533.99/linux64/chromedriver-linux64.zip \
&& unzip chromedriver-linux64.zip \
&& rm chromedriver-linux64.zip \
&& mv chromedriver-linux64/chromedriver /usr/bin/chromedriver
Expand Down
14 changes: 4 additions & 10 deletions html_to_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ def to_pdf(html: str) -> bytes:
chrome_options = build_chrome_options()
executable_path = os.environ.get("CHROMEDRIVER_PATH") or "/usr/bin/chromedriver"
output = b""

driver = None
try:
driver = webdriver.Chrome(executable_path=executable_path, chrome_options=chrome_options)
driver = webdriver.Chrome(
executable_path=executable_path, chrome_options=chrome_options
)
except Exception as e:
logger.error(e)

Expand All @@ -42,16 +44,8 @@ def to_pdf(html: str) -> bytes:
def build_chrome_options():
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--no-zygote")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--single-process")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--disable-dev-profile")
chrome_options.add_argument("--disable-web-security")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--disable-gpu-rasterization")
chrome_options.add_argument("--disable-software-rasterizer")

chrome_options.binary_location = (
os.environ.get("CHROME_BINARY") or "/opt/google/chrome/chrome"
Expand Down

0 comments on commit e7f7dfd

Please sign in to comment.