question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Switch the default driver for export_png to chromedriver

See original GitHub issue

Started at #5714. All relevant details are repeated here.

PhantomJS is no longer maintained, and at this point using it produces PNGs like these: (a fragment with y-axis) image (a fragment with x-axis with rotated labels) image Using normal font instead of the italic one does not mitigate the issue.

Currently, I’m using this code to create a driver instance and pass it down to export_png:

import os
import shutil

from chromedriver_binary.utils import get_chromedriver_path
from selenium.webdriver import Chrome, ChromeOptions

options = ChromeOptions()
# TODO: Remove when https://bugs.chromium.org/p/chromium/issues/detail?id=875241 is fixed
options.binary_location = shutil.which('chrome')

options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument("--no-sandbox")
options.add_argument("--window-size=2000x2000")

web_driver = Chrome(executable_path=os.path.join(get_chromedriver_path(), 'chromedriver'),
                    chrome_options=options)

chromedriver_binary is available by installing python-chromedriver-binary from the conda-forge channel. I tested my code with version 2.41.0.

There’s a few of issues:

  1. Google Chrome can be available under names other than chrome
  2. There’s no check for Google Chrome version
  3. The fixed window size, 2000x2000. It probably could be somehow computed in advance
  4. Need to check whether this could be used with Chromium - many people use it instead of Google Chrome

Also, maybe at some point there could be a simple option that would use Firefox, but right now it appears to be unusable as it complains about missing log command.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
bryevdvcommented, Sep 12, 2018

Here is a complete example that sets the device pixel ratio to 1.0 to get a correctly scaled image on OSX:

from selenium.webdriver import Chrome, ChromeOptions

options = ChromeOptions()

options.add_argument('--headless')
options.add_argument("--window-size=2000x2000")
metrics = { "deviceMetrics": { "pixelRatio": 1.0 } }
options.add_experimental_option("mobileEmulation", metrics)
web_driver = Chrome(chrome_options=options)

import numpy as np

from bokeh.plotting import figure, show, output_file

N = 4000
x = np.random.random(size=N) * 100
y = np.random.random(size=N) * 100
radii = np.random.random(size=N) * 1.5
colors = [
    "#%02x%02x%02x" % (int(r), int(g), 150) for r, g in zip(50+2*x, 30+2*y)
]

p = figure(tools="")

p.circle(x, y, radius=radii,
          fill_color=colors, fill_alpha=0.6,
          line_color=None)

from bokeh.io import export_png

export_png(p, "out.png", webdriver=web_driver)

out

It’s unclear to me yet if just unconditionally setting to 1.0 is always the correct thing to do, or if it is a specific action for a macbook w retina display.

0reactions
mattpapcommented, Feb 29, 2020

This was resolved in PR #9331.

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to change file download location in Webdriver while ...
CAPABILITY, options); WebDriver driver = new ChromeDriver(cap); ... turn off the download prompt if it appears; set the default directory to ...
Read more >
Open, save, or delete files - Chromebook Help
Save a file · On your computer, open Chrome. · At the top right, select More More and then Settings. · At the...
Read more >
Most Complete Selenium WebDriver C# Cheat Sheet
Chrome ;. IWebDriver driver = new ChromeDriver();. // NuGet: Selenium.Mozilla. ... Switch to the default document ... Change the default files' save location....
Read more >
Adjusting zoom settings in Chrome browser
By default, Chrome sets the zoom level to 100%. To manually adjust the settings, use the Ctrl key and “+” or “-” combos...
Read more >
Exporting plots — Bokeh 2.4.3 Documentation
geckodriver for Firefox. ChromeDriver for Chrome / Chromium. You can install these dependencies in various ways. The recommended way is to use conda ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found