Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix headless rendering with latest chrome #361

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions ipyvolume/headless.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,20 @@ def _screenshot_data(
# else:
# assert isinstance(fig, ipv.Figure)

chrome = PyChromeDevTools.ChromeInterface(headless_kwargs)

try:
host = "localhost"
port = 9222

if headless_kwargs.get("host"):
host = headless_kwargs.get("host")
rafique marked this conversation as resolved.
Show resolved Hide resolved

chrome = PyChromeDevTools.ChromeInterface(host=host, port=port)
#chrome = PyChromeDevTools.ChromeInterface(host="localhost")
rafique marked this conversation as resolved.
Show resolved Hide resolved
except:
print("Falied to connect to headless chrome, please make sure it's running on host={} and port={}".format(host, port))
raise

chrome.Network.enable()
chrome.Page.enable()
chrome.Page.navigate(url=html_filename)
Expand All @@ -59,16 +72,19 @@ def _screenshot_data(
result = chrome.Runtime.evaluate(expression='ipvss()')
tries = 0
while tries < 10:
#print(str(result))
try:
url = result['result']['result']['value']
url = result[0]['result']['result']['value']
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did this change, and which version, and can we make it detect this? so it also works on older versions?

Copy link
Author

@rafique rafique Jan 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I don't know why/when this has changed. This seems to work fine but recently throwing the following error: "tuple indices must be integers or slices, not str". This is the main reason prompting this pull request. Since there has been no recent update to ipyvolume python module, my guess is that something else (chrome/ipyvolume js module/threejs) has been updated

return url
except:
if 'ipvss' in result['result']['result']['description']:
except Exception as ex:
#print(str(ex))
#raise ex
rafique marked this conversation as resolved.
Show resolved Hide resolved
if 'ipvss' in result[0]['result']['result']['description']:
rafique marked this conversation as resolved.
Show resolved Hide resolved
tries += 1
time.sleep(0.5)
else:
print('error getting result, return value was:', result)
raise
raise ex
rafique marked this conversation as resolved.
Show resolved Hide resolved


def _main():
Expand Down