Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.0 - firefox pdf fails when printBackground set to true #5671

Closed
kumar-muthu opened this issue Apr 17, 2020 · 5 comments
Closed

v3.0 - firefox pdf fails when printBackground set to true #5671

kumar-muthu opened this issue Apr 17, 2020 · 5 comments

Comments

@kumar-muthu
Copy link

Steps to reproduce

  • Puppeteer version: 3.0
  • Platform / OS version: macOs Mojave
  • Node.js version: 12.16.1

What steps will reproduce the problem?

  1. test.html
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=800, height=800">
    <style>
        .bg {
            background-image: url('https://images.unsplash.com/photo-1586973699006-2a096c90f847?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2734&q=80');
            height: 800px;
            width: 800px;
            background-size: cover;
        }
    </style>
</head>
<body>
<div class="bg"></div>
</body>
</html>
  1. js code
const puppeteer = require('puppeteer');
const firefoxOptions = {
    product: 'firefox',
    extraPrefsFirefox: {
        // Enable additional Firefox logging from its protocol implementation
         'remote.log.level': 'Trace',
    },
    // Make browser logs visible
    dumpio: true,
};

(async() => {
    const browser = await puppeteer.launch(firefoxOptions);
    const page = await browser.newPage();
    await page.pdf({
        printBackground: true, // when set to false, there is no issue
        path: 'hn.pdf'});
    await browser.close();
})();

What is the expected result?
Convert to pdf without issues

What happens instead?
It results in the following error

1587125621499   RemoteAgent     TRACE   (connection {c236c872-af3d-7f40-8239-c03ac2d5072c})-> {"sessionId":1,"method":"Page.printToPDF","params":{"transferMode":"ReturnAsStream","landscape":false,"displayHeaderFooter":false,"headerTemplate":"","footerTemplate":"","printBackground":true,"scale":1,"paperWidth":8.5,"paperHeight":11,"marginTop":0,"marginBottom":0,"marginLeft":0,"marginRight":0,"pageRanges":"","preferCSSPageSize":false},"id":18}
1587125622620   RemoteAgent     TRACE   <-(connection {c236c872-af3d-7f40-8239-c03ac2d5072c}) {"sessionId":1,"id":18,"result":{"data":null,"stream":"18c71222-e870-4f4d-b68b-11f51869596a"}}
1587125622632   RemoteAgent     TRACE   (connection {c236c872-af3d-7f40-8239-c03ac2d5072c})-> {"sessionId":1,"method":"IO.read","params":{"handle":"18c71222-e870-4f4d-b68b-11f51869596a"},"id":19}
1587125622640   RemoteAgent     TRACE   <-(connection {c236c872-af3d-7f40-8239-c03ac2d5072c}) {"id":19,"sessionId":1,"error":{"message":"too many arguments provided for a function call","data":"read@chrome://remote/cont ... dy@chrome://remote/content/server/HTTPD.jsm:1632:14\nonInputStreamReady@chrome://remote/content/server/HTTPD.jsm:1511:14\n"}}
(node:95348) UnhandledPromiseRejectionWarning: Error: Protocol error (IO.read): too many arguments provided for a function call read@chrome://remote/content/domains/parent/IO.jsm:105:43
async*execute@chrome://remote/content/domains/DomainCache.jsm:99:25
execute@chrome://remote/content/sessions/Session.jsm:54:25
execute@chrome://remote/content/sessions/TabSession.jsm:67:20
onPacket@chrome://remote/content/Connection.jsm:225:36
onMessage@chrome://remote/content/server/WebSocketTransport.jsm:85:18
handleEvent@chrome://remote/content/server/WebSocketTransport.jsm:67:14
EventListener.handleEvent*ready@chrome://remote/content/server/WebSocketTransport.jsm:29:17
Connection@chrome://remote/content/Connection.jsm:38:20
handle@chrome://remote/content/targets/Target.jsm:56:18
async*createHandlerFunc/<@chrome://remote/content/server/HTTPD.jsm:2120:13
handleResponse@chrome://remote/content/server/HTTPD.jsm:2445:36
process@chrome://remote/content/server/HTTPD.jsm:1340:26
_handleResponse@chrome://remote/content/server/HTTPD.jsm:1787:22
_processBody@chrome://remote/content/server/HTTPD.jsm:1632:14
onInputStreamReady@chrome://remote/content/server/HTTPD.jsm:1511:14

    at /Users/kumar/sandboxes/rasPDF/node_modules/puppeteer/lib/Connection.js:173:63
    at new Promise (<anonymous>)
    at CDPSession.send (/Users/kumar/sandboxes/rasPDF/node_modules/puppeteer/lib/Connection.js:172:16)
    at Function.readProtocolStream (/Users/kumar/sandboxes/rasPDF/node_modules/puppeteer/lib/helper.js:241:43)
    at async Page.pdf (/Users/kumar/sandboxes/rasPDF/node_modules/puppeteer/lib/Page.js:917:16)
    at async /Users/kumar/sandboxes/rasPDF/app/raster/raw_firefox.js:56:5
  -- ASYNC --
    at Page.<anonymous> (/Users/kumar/sandboxes/rasPDF/node_modules/puppeteer/lib/helper.js:105:23)
    at /Users/kumar/sandboxes/rasPDF/app/raster/raw_firefox.js:56:16
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:95348) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:95348) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
@kumar-muthu kumar-muthu changed the title firefox pdf fails when printBackground set to true v3.0 - firefox pdf fails when printBackground set to true Apr 19, 2020
@mjzffr mjzffr added the firefox label Apr 24, 2020
@mjzffr
Copy link
Contributor

mjzffr commented Apr 24, 2020

Thanks for the great bug report. Filed this as https://bugzilla.mozilla.org/show_bug.cgi?id=163272

If you hit any other protocol errors in Firefox while using Puppeteer v3, feel free to file issues here or directly in https://bugzilla.mozilla.org under the "Remote Protocol" product.

@whimboo
Copy link
Collaborator

whimboo commented Jun 2, 2020

Note that the referenced Bugzilla link points to a different bug. Here is the correct one:

https://bugzilla.mozilla.org/show_bug.cgi?id=1632722

@logycware
Copy link

it seems that the problem is related to the size of the generated PDF. Making a change on helper.js (readProtocolStream), specifying the size parameter solved the problem.

const response = await client.send ('IO.read', {handle: handle, size: 102400});

@logycware
Copy link

logycware commented Jul 23, 2020

pull request #6264

@mjzffr
Copy link
Contributor

mjzffr commented Aug 10, 2020

Should be fixed in the next Firefox Nightly: https://bugzilla.mozilla.org/show_bug.cgi?id=1632722

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants