debug_screenshot.py aktualisiert
This commit is contained in:
@@ -1,12 +1,14 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from pyppeteer import launch
|
from pyppeteer import launch
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
# Logging-Konfiguration
|
# Logging-Konfiguration
|
||||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||||
|
|
||||||
HA_URL = "http://192.168.178.131:8123/lovelace/solar?kiosk"
|
HA_URL = "http://192.168.178.131:8123/lovelace/solar?kiosk"
|
||||||
OUTPUT_FILE = "/screenshots/debug_screenshot.png"
|
OUTPUT_FILE = "/screenshots/debug_screenshot.png"
|
||||||
|
HA_TOKEN = os.environ.get("HA_ACCESS_TOKEN")
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
logging.info("Starte Puppeteer-Browser...")
|
logging.info("Starte Puppeteer-Browser...")
|
||||||
@@ -40,5 +42,42 @@ async def main():
|
|||||||
logging.info("Schließe Browser.")
|
logging.info("Schließe Browser.")
|
||||||
await browser.close()
|
await browser.close()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
async def main():
|
||||||
asyncio.run(main())
|
logging.info("Starte Puppeteer-Browser...")
|
||||||
|
browser = await launch(
|
||||||
|
executablePath='/usr/bin/chromium',
|
||||||
|
headless=True,
|
||||||
|
args=['--no-sandbox', '--disable-setuid-sandbox']
|
||||||
|
)
|
||||||
|
|
||||||
|
page = await browser.newPage()
|
||||||
|
await page.setViewport({'width': 1280, 'height': 1024})
|
||||||
|
|
||||||
|
# NEU: Authentifizierungs-Header für alle Anfragen dieser Seite setzen
|
||||||
|
if HA_TOKEN:
|
||||||
|
logging.info("Authentifizierungs-Token gefunden. Setze 'Authorization'-Header.")
|
||||||
|
await page.setExtraHTTPHeaders({
|
||||||
|
'Authorization': f'Bearer {HA_TOKEN}'
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
logging.warning("Kein HA_ACCESS_TOKEN gefunden. Versuche unauthentifizierten Zugriff.")
|
||||||
|
|
||||||
|
try:
|
||||||
|
logging.info(f"Navigiere zu URL: {HA_URL}")
|
||||||
|
await page.goto(HA_URL, {'waitUntil': 'networkidle0', 'timeout': 60000})
|
||||||
|
|
||||||
|
logging.info("Seite geladen. Warte 10 Sekunden, um Rendering abzuwarten...")
|
||||||
|
await asyncio.sleep(10)
|
||||||
|
|
||||||
|
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}")
|
||||||
|
logging.info("Speichere trotzdem einen Screenshot des aktuellen Zustands...")
|
||||||
|
await page.screenshot({'path': '/screenshots/debug_error.png'})
|
||||||
|
|
||||||
|
finally:
|
||||||
|
logging.info("Schließe Browser.")
|
||||||
|
await browser.close()
|
||||||
Reference in New Issue
Block a user