Rendering Timed Out

by ADMIN 20 views

Introduction

In this article, we will delve into the issue of rendering timed out when using hass-screenshot in a Docker container to capture a Lovelace dashboard from Home Assistant. We will explore the possible causes, questions, and potential solutions to resolve this issue.

To Reproduce

To reproduce the behavior, follow these steps:

Step 1: Run hass-screenshot in a Docker container

Run the following command to start the hass-screenshot container:

docker run -e HA_BASE_URL="https://floke.duckdns.org" \
           -e HA_SCREENSHOT_URL="/lovelace/4" \
           -e HA_ACCESS_TOKEN="MY_LONG_LIVED_ACCESS_TOKEN" \
           -e PUPPETEER_TIMEOUT=30000 \
           lanrat/hass-screenshot:latest

Step 2: Verify authentication

The logs will indicate that authentication appears to be successful:

[3/12/2025, 2:26:55 PM] Visiting 'https://floke.duckdns.org' to login...
[3/12/2025, 2:26:57 PM] Adding authentication entry to browser's local storage...

Step 3: Observe rendering failure

However, the rendering consistently fails with a timeout:

[3/12/2025, 2:26:57 PM] Rendering https://floke.duckdns.org/lovelace/4 to image...
[3/12/2025, 2:27:10 PM] Failed to render https://floke.duckdns.org/lovelace/4
[3/12/2025, 2:27:10 PM] Error: TimeoutError: waiting for selector `home-assistant` failed: timeout exceeded

Step 4: Verify page reachability

Running wget inside the container shows that the page is reachable:

wget --no-check-certificate -O - https://floke.duckdns.org

This returns valid HTML from Home Assistant.

Expected Behavior

Puppeteer should be able to fully load and render the Lovelace dashboard without timing out.

What I Have Tried So Far

Increased PUPPETEER_TIMEOUT

Increased PUPPETEER_TIMEOUT to 30000ms → No change.

Tried different Lovelace dashboards

Tried different Lovelace dashboards (/lovelace/0, /lovelace/solar, /lovelace/default_view) → No change.

Removed ?kiosk from the URL

Removed ?kiosk from the URL → No change.

Tried using the local IP

Tried using the local IP (http://192.168.x.x:8123) instead of DuckDNS → No change.

Enabled Puppeteer Debug Mode

Enabled Puppeteer Debug Mode (export DEBUG="puppeteer:*") → Confirmed Puppeteer gets redirected to /auth/authorize.

Tried setting PUPPETEER_HEADLESS=false

Tried setting PUPPETEER_HEADLESS=false → Unable to confirm behavior without UI.

Possible Causes & Questions

Why is Puppeteer redirected to /auth/authorize?

Despite setting HA_ACCESS_TOKEN, Puppeteer is redirected to /auth/authorize. Is this a known issue?

Is there a way to persist authentication in Puppeteer?

Is there a way to persist authentication in Puppeteer to avoid re-login issues?

Could X-Frame-Options or CSP policies in Home Assistant be blocking Puppeteer?

Could X-Frame-Options or CSP policies in Home Assistant be blocking Puppeteer from rendering the page?

Are there known issues with capturing specific Lovelace views?

Are there known issues with capturing specific Lovelace views (/lovelace/4)?

Would manually injecting the token into Puppeteer’s session storage help?

Would manually injecting the token into Puppeteer’s session storage help resolve the issue?

System Information

Docker environment

Docker environment: Synology NAS

Container

Container: lanrat/hass-screenshot:latest

Home Assistant

Home Assistant: Running via DuckDNS with Let's Encrypt SSL

Puppeteer Timeout

Puppeteer Timeout: 30000ms

Logs & Debug Output

If needed, I can provide full logs and debug output.

Conclusion

Q: What is the issue with rendering timed out when using hass-screenshot in a Docker container?

A: The issue is that Puppeteer is unable to fully load and render the Lovelace dashboard without timing out. Despite setting HA_ACCESS_TOKEN, Puppeteer is redirected to /auth/authorize, and the rendering consistently fails with a timeout.

Q: What are the possible causes of this issue?

A: The possible causes of this issue include:

  • Puppeteer redirected to /auth/authorize: Despite setting HA_ACCESS_TOKEN, Puppeteer is redirected to /auth/authorize. Is this a known issue?
  • X-Frame-Options or CSP policies in Home Assistant: Could X-Frame-Options or CSP policies in Home Assistant be blocking Puppeteer from rendering the page?
  • Known issues with capturing specific Lovelace views: Are there known issues with capturing specific Lovelace views (/lovelace/4)?
  • Puppeteer authentication issues: Is there a way to persist authentication in Puppeteer to avoid re-login issues?

Q: How can I troubleshoot this issue?

A: To troubleshoot this issue, you can try the following:

  • Increase PUPPETEER_TIMEOUT: Increase PUPPETEER_TIMEOUT to 30000ms to see if it resolves the issue.
  • Try different Lovelace dashboards: Try different Lovelace dashboards (/lovelace/0, /lovelace/solar, /lovelace/default_view) to see if the issue is specific to a particular dashboard.
  • Remove ?kiosk from the URL: Remove ?kiosk from the URL to see if it resolves the issue.
  • Try using the local IP: Try using the local IP (http://192.168.x.x:8123) instead of DuckDNS to see if it resolves the issue.
  • Enable Puppeteer Debug Mode: Enable Puppeteer Debug Mode (export DEBUG="puppeteer:*") to see if it provides any additional information about the issue.
  • Try setting PUPPETEER_HEADLESS=false: Try setting PUPPETEER_HEADLESS=false to see if it resolves the issue.

Q: Can I manually inject the token into Puppeteer’s session storage?

A: Yes, you can manually inject the token into Puppeteer’s session storage. This may help resolve the issue.

Q: What are the system requirements for this issue?

A: The system requirements for this issue include:

  • Docker environment: Docker environment: Synology NAS
  • Container: Container: lanrat/hass-screenshot:latest
  • Home Assistant: Home Assistant: Running via DuckDNS with Let's Encrypt SSL
  • Puppeteer Timeout: Puppeteer Timeout: 30000ms

Q: Can I provide full logs and debug output?

A: Yes, you can provide full logs and debug output if needed.

Q: What are the next steps to resolve this issue?

A: The next steps to resolve this issue include:

  • Investigate Puppeteer authentication issues: Investigate Puppeteer authentication issues to see if it is the root cause of the problem.
  • Check X-Frame-Options or CSP policies in Home Assistant: Check X-Frame-Options or CSP policies in Home Assistant to see if they are blocking Puppeteer from rendering the page.
  • Try manually injecting the token into Puppeteer’s session storage: Try manually injecting the token into Puppeteer’s session storage to see if it resolves the issue.