debug_screenshot.py aktualisiert
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
import asyncio
|
||||
import os
|
||||
import json
|
||||
import logging
|
||||
from pyppeteer import launch
|
||||
|
||||
# Logging-Konfiguration
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
|
||||
# --- Konfiguration ---
|
||||
HA_URL = "http://192.168.178.131:8123/lovelace/solar?kiosk"
|
||||
OUTPUT_FILE = "/screenshots/hass_screenshot.png"
|
||||
# Token direkt aus der Umgebungsvariable holen
|
||||
HA_TOKEN = os.environ.get("HA_ACCESS_TOKEN")
|
||||
|
||||
# URL wird dynamisch mit dem Token zusammengesetzt
|
||||
HA_URL = f"http://192.168.178.131:8123/lovelace/solar?kiosk&auth_callback=1&access_token={HA_TOKEN}"
|
||||
OUTPUT_FILE = "/screenshots/final_screenshot.png"
|
||||
|
||||
async def main():
|
||||
if not HA_TOKEN:
|
||||
logging.error("Fehler: Umgebungsvariable HA_ACCESS_TOKEN nicht gefunden!")
|
||||
@@ -21,44 +21,25 @@ async def main():
|
||||
browser = await launch(
|
||||
executablePath='/usr/bin/chromium',
|
||||
headless=True,
|
||||
ignoreHTTPSErrors=True,
|
||||
args=['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage']
|
||||
args=['--no-sandbox', '--disable-setuid-sandbox']
|
||||
)
|
||||
|
||||
page = await browser.newPage()
|
||||
await page.setViewport({'width': 1280, 'height': 1024})
|
||||
|
||||
try:
|
||||
# === NEU: TOKEN-INJEKTION IN DEN LOCAL STORAGE ===
|
||||
# Dieses JavaScript wird ausgeführt, bevor die Ziel-URL geladen wird.
|
||||
# Es erstellt den Authentifizierungs-Eintrag, den Home Assistant erwartet.
|
||||
logging.info("Injiziere Authentifizierungs-Token in den Local Storage des Browsers...")
|
||||
await page.evaluateOnNewDocument(f'''
|
||||
localStorage.setItem(
|
||||
'hassio-token',
|
||||
JSON.stringify({{
|
||||
'access_token': '{HA_TOKEN}',
|
||||
'token_type': 'Bearer',
|
||||
'expires_in': 86400, // Gültigkeit auf 24h setzen
|
||||
'expires': new Date().getTime() + 86400 * 1000,
|
||||
'hassUrl': 'http://192.168.178.131:8123'
|
||||
}})
|
||||
);
|
||||
''')
|
||||
|
||||
logging.info(f"Navigiere zur finalen URL: {HA_URL}")
|
||||
logging.info(f"Navigiere direkt zur authentifizierten URL...")
|
||||
await page.goto(HA_URL, {'waitUntil': 'networkidle0', 'timeout': 60000})
|
||||
|
||||
logging.info("Seite geladen. Warte 15 Sekunden auf das finale Rendering aller Elemente...")
|
||||
await asyncio.sleep(15) # Großzügige Wartezeit für komplexe Dashboards
|
||||
logging.info("Seite geladen. Warte 15 Sekunden auf das finale Rendering...")
|
||||
await asyncio.sleep(15)
|
||||
|
||||
logging.info("Erstelle finalen Screenshot...")
|
||||
logging.info("Erstelle Screenshot...")
|
||||
await page.screenshot({'path': OUTPUT_FILE})
|
||||
logging.info(f"Screenshot erfolgreich unter {OUTPUT_FILE} gespeichert.")
|
||||
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"Ein Fehler ist aufgetreten: {e}", exc_info=True)
|
||||
logging.info("Speichere Screenshot des Fehler-Zustands...")
|
||||
await page.screenshot({'path': '/screenshots/debug_error_final.png'})
|
||||
|
||||
finally:
|
||||
@@ -66,7 +47,4 @@ async def main():
|
||||
await browser.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
asyncio.run(main())
|
||||
except Exception as e:
|
||||
logging.critical(f"Kritischer Fehler im Hauptprozess: {e}", exc_info=True)
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user