question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can not render a WebGL image for PDF -- get a black box instead

See original GitHub issue

Summary:

I am trying to get a PDF of a page that has a panoramic image on it using Puppeteer. The panoramic image is rendered using WebGL, which I suspect to be the issue. All I get is a black box instead of the image (see the bottom of this post for screen image). But, I can use Puppeteer to get a screenshot of that same page and the panorama looks great. I am not sure why it won’t render when I attempt getting a PDF, but works for screenshot.

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: puppeteer@0.10.2
  • Platform / OS version: Linux c1301da96bb5 4.9.49-moby running in a Docker container
  • URLs (if applicable):
  • Node.js version: 8.8.1 (NOTE: the code below was originally developed in 6.1, but we now run 8.8.1)

What steps will reproduce the problem?

Please include code that reproduces the issue.

  1. Using this code:
var page, browser;
return Puppeteer.launch({args: options.chromeArgs})
    .then(res => {
        if (!res) {
            return reject(new Error("No browser to open"));
        }
        browser = res;
        return browser.newPage();
    })
    .then(res => {
        if (!res) {
            throw new Error("No browswer available");
         }
        page = res;
        return page.setViewport({
            height: 720,
            width: 1280,
            isLandscape: true,
        ));
    })
    .then(() => {
        return page.goto(url,{"waitUntil":"networkidle0"});
    })
    .then(() => {
        return page.pdf(options);
    })
    .then(buffer => {
       if (browser) {
           browser.close();
       }
       return resolve(buffer);
    })
    .catch(err => {
        if (browser) {
            browser.close();
        }
        return reject(err);
    });
  1. I have tried these options:
            "pageTimeout": 120000,
            "chromeArgs": ["--disable-gpu","--disable-setuid-sandbox","--no-sandbox"],
            "headless": true,
            "printBackground": true,
            "displayHeaderFooter": true,
            "landscape": true,
            "margin": {
                "top": 0,
                "bottom": 0,
                "left": 0,
                "right": 0
            }
        }
  1. I have also tried adding these the the chromeArgs: --use-gl=swiftshader --use-gl=osmesa --use-gl=swiftshader-webgl

What is the expected result? I would expect the PDF to look like the screenshot – like this 004

Here is the screenshot from Puppeteer (NOTE: the html page is formatted slightly differently for PDF rendering, but the panoramic image is the same) 0002

What happens instead? The PDF has a black box where the panoramic image should be. 003

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:4
  • Comments:33 (5 by maintainers)

github_iconTop GitHub Comments

9reactions
pguardiariocommented, Jun 19, 2021

For some reason the mapbox issue affects pdf but not screenshots, so my workaround was to replace canvases with screenshots:

let canvases = await page.$$('canvas')
for(let canvas of canvases){
    let str = await canvas.screenshot({ encoding: "base64" })
    let dataUrl = 'data:image/png;base64,' + str
    await canvas.evaluate((canvas, dataUrl) => {
      const newDiv = document.createElement('div')
      newDiv.innerHTML = '<img src="' + dataUrl + '">'
      canvas.parentNode.replaceChild(newDiv, canvas)
    }, dataUrl)
}
6reactions
andrewharveycommented, Dec 16, 2018

@ianformanek Make sure you’re using preserveDrawingBuffer: true.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Black box instead of the image in canvas - Stack Overflow
Maybe because you draw the image before it's loaded. I have found this exemple : https://stackoverflow.com/a/24997626/9231356. Hope it will ...
Read more >
Black boxes show around images when I convert from...
When I convert from Word to PDF the images come out with black boxes around them or completely blacked out. How do I...
Read more >
Techniques for Rendering Text with WebGL - CSS-Tricks
The text can't be occluded with the 3D geometry as an overlay, but you can get styling and accessibility out of the box....
Read more >
Interactive 3D Graphics Programming with WebGL
WebGL is a vital part of HTML5, as it enables web programmers to access the ... make no expressed or implied warranty of...
Read more >
WebGL Beginner's Guide.pdf - uniguld
you this book would not had been a reality. ... WebGL does not have cameras ... When the image that needs to be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found