Open basilevh opened 2 years ago
Hi @basilevh, thank you for your feedback.
I ran the headless.ipynb
notebook on my laptop (Fedora 37, Python 3.10.4, Firefox 100) with the same 2.14.1 version and everything word fine on my side.
However I already had this error message several time while working with headless.sync()
but this wasn't always automatic.
The more plausible answer I thought this issue may come from must have something to do with your browser / Jupyter Notebook configuration (cache management, installed extension, ...).
Most of the time, rebooting my laptop solve the issue for me.
I'm battling with the same problem. With trials and errors I understood that:
Now to the funny behavior: let's say I'm trying to generate some screenshots in headless mode with Chrome. The first time executing a script always works fine. From the second time, the above errors start displaying at random. Now, If I change the browser to headless Firefox everything works fine. Then, If I switch back to headless Chrome, again the first time always works fine. From the second time the above errors start displaying at random... It's weird, it's like Chrome stores some memory from different sessions. I've tried resetting the cache between executions, both it doesn't help.
Also note that that options like "--disable-dev-shm-usage"
or "--no-sandbox"
always make Chrome headless to raise that error.
I was having the same issue on MacOS when running the headless.ipynb notebook in VSCode. Since my main browser is Firefox I decided to see if using Firefox instead of Chrome would help. I edited k3d/headless.py in my site-package to add this new function:
def get_headless_firefox_driver(no_headless=False):
from selenium import webdriver
from selenium.webdriver.firefox.service import Service as FirefoxService
from webdriver_manager.firefox import GeckoDriverManager
options = webdriver.FirefoxOptions()
options.add_argument("--no-sandbox")
if not no_headless:
options.add_argument("--headless")
return webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()),
options=options)
and then replaced the import and call to get_headless_driver
with get_headless_firefox_driver
.
It worked perfectly.
In an ideal world get_headless_driver
would have a default of chrome but could accept other browsers if users want.
Thanks @dazzag24 ! I like idea to not force chrome. I will add it to official k3d package!
Hi! Please check https://pypi.org/project/k3d/2.16.1/ :)
I can reproduce the Firefox problem with jupyter on docker and readthedocs (ie Ubuntu), with the same behavior.
Using Firefox fails with ReferenceError: k3dRefresh is not defined
: see https://spanag-rtd-tutorial.readthedocs.io/en/latest/headless_k3d.html .
If Chrome or Chromium is installed (from a deb file bc snap doesn't work on Docker sadly) the same notebook (with the get_headless_driver
that is) is nbexport
ed fine (but can't be used on readthedocs).
When I try to run https://github.com/K3D-tools/K3D-jupyter/blob/main/examples/headless.ipynb via Jupyter notebook on a remote Ubuntu 20.04.4 LTS machine with Python 3.7.13 and k3d 2.14.1 installed, calling
headless.sync()
triggers the following rather hard to interpret error:Any help is appreciated. Thanks!