Skip to content

Commit

Permalink
Added waiting for CSS file to be loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
frzb committed Jan 23, 2025
1 parent 5383f8a commit 184157b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ def create_pdf(self, url, file_name):
page.emulate_media(media="print")
# Waiting for the side to be loaded matters, else the fallback font is applied
page.wait_for_function("document.fonts.status === 'loaded'")
# Wait for the CSS file to load
page.wait_for_function("""
() => {
const link = [...document.querySelectorAll('link[rel="stylesheet"]')].find(
l => l.href.includes('tailwind.css')
);
return link && link.sheet;
}
""")
print("CSS file has loaded!")
page.wait_for_load_state("networkidle")
page.pdf(path=f"./output/{file_name}.pdf", format="A4",landscape=False, margin={"top": "2cm"})
browser.close()
Expand Down

0 comments on commit 184157b

Please sign in to comment.