various small bugfixes; add cards list view
This commit is contained in:
parent
d5f8345581
commit
05a279fa3a
10 changed files with 264 additions and 23 deletions
|
|
@ -618,26 +618,60 @@ class TradeOfferPNGView(View):
|
|||
|
||||
html = render_to_string("templatetags/trade_offer_png.html", tag_context)
|
||||
|
||||
# If there's a query parameter 'debug' set to true, render the HTML to the response.
|
||||
if request.GET.get('debug'):
|
||||
return HttpResponse(html, content_type="text/html")
|
||||
|
||||
css = render_to_string("static/css/dist/styles.css")
|
||||
|
||||
# Launch Playwright to render the HTML and capture a screenshot.
|
||||
with sync_playwright() as p:
|
||||
print("Launching browser")
|
||||
browser = p.chromium.launch(
|
||||
headless=True,
|
||||
args=[
|
||||
"--disable-gpu",
|
||||
"--no-sandbox",
|
||||
'--disable-setuid-sandbox',
|
||||
'--disable-dev-shm-usage',
|
||||
'--disable-accelerated-2d-canvas',
|
||||
'--no-first-run',
|
||||
'--disable-gpu'
|
||||
"--disable-setuid-sandbox",
|
||||
"--disable-dev-shm-usage",
|
||||
"--disable-accelerated-2d-canvas",
|
||||
"--disable-gpu",
|
||||
#"--single-process",
|
||||
"--no-zygote",
|
||||
"--disable-audio-output",
|
||||
#"--disable-software-rasterizer",
|
||||
"--disable-webgl",
|
||||
#"--disable-web-security",
|
||||
#"--disable-features=LazyFrameLoading",
|
||||
#"--disable-features=IsolateOrigins",
|
||||
#"--disable-background-networking",
|
||||
"--no-first-run",
|
||||
]
|
||||
)
|
||||
print("Launched browser, creating context")
|
||||
context_browser = browser.new_context(viewport={"width": image_width, "height": image_height})
|
||||
print("Created context, creating page")
|
||||
page = context_browser.new_page()
|
||||
page.set_content(html, wait_until="networkidle")
|
||||
print("Created page, setting content")
|
||||
|
||||
# Listen for all console logs, errors, and warnings
|
||||
page.on("console", lambda msg: print(f"Console {msg.type}: {msg.text}"))
|
||||
page.on("pageerror", lambda err: print(f"Page error: {err}"))
|
||||
|
||||
# Listen specifically for failed resource loads
|
||||
page.on("requestfailed", lambda request: print(f"Failed to load: {request.url} - {request.failure.error_text}"))
|
||||
|
||||
# # Instead of using a link tag, let's inject the CSS directly
|
||||
# css = render_to_string("static/css/dist/styles.css")
|
||||
# page.add_style_tag(content=css)
|
||||
|
||||
page.set_content(html, wait_until="domcontentloaded")
|
||||
print("Set content, waiting for element")
|
||||
element = page.wait_for_selector(".trade-offer-card-screenshot")
|
||||
print("Found element, capturing screenshot")
|
||||
screenshot_bytes = element.screenshot(type="png", omit_background=True)
|
||||
print("Captured screenshot, closing browser")
|
||||
browser.close()
|
||||
print("Closed browser, returning screenshot")
|
||||
|
||||
return HttpResponse(screenshot_bytes, content_type="image/png")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue