Grafana + Playwright + Docker Problems
I am using Grafana to graph one of my applications, and I wanted to export these graphs to PDF and email them periodically.
I decidede to use playwright, which is a testing framework that uses a real browser engine and run it without user interface, and it support PDF printing too (only chromium engine).
I used the following Python code:
import time
from playwright.sync_api import sync_playwright
def print_reports():
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
ctx = browser.new_context()
page = ctx.new_page()
page.goto(f"http://nginx/grafana/")
time.sleep(2)
page.pdf(path="report.pdf")
browser.close()
It worked perfeclty from my Mac, but when I tried the same code from the container, grafana started to misbehave and give this error:
If you’re seeing this Grafana has failed to load its application files
After many trial and errors, I added the following line to my code to show and page loading issues:
page.on("pageerror", lambda exc: print(f"uncaught exception: {exc}"))
and I got this error:
uncaught exception: Invalid language tag: en-US@posix
So the problem was with default language setting in the container, to
resolve it I added a locale
argument to the context creattion:
ctx = browser.new_context(locale="en-US")