pofider / phantom-html-to-pdf

Highly scalable html to pdf conversion using phantom workers
MIT License
159 stars 33 forks source link

How to send cookies when accessing images on a page #65

Closed CROSP closed 7 years ago

CROSP commented 7 years ago

Hi, thanks for a great library. It works, but I have the problem. When requests for images are made ( tags) cookies are not sent and headers as well.

Here is an example.

 return htmlToPdf(
            {
                settings: {
                    javascriptEnabled: true,
                    resourceTimeout: 10000
                },

                cookies: [{
                    name: 'cookie-name',
                    value: 'cookie-value',
                    path: '/',
                    domain: 'domain.com'//Leave blank when working on localhost - "." will get prepended to domain
                }],
                customHeaders: headers,
                html: html,
                format: {
                    quality: 100
                }
            },
            function (err, pdf) {
                console.log(pdf.logs);
                console.log(pdf.numberOfPages);
                pdf.stream.pipe(writableStream).on('finish', () => {
                    callback(filename);
                });
            });

I have tried to debug requests using an intercepting proxy software, but neither headers nor cookies are sent when requests are made to download images.

How this problem can be solved ?

pofider commented 7 years ago

Hm, we add cookies to phantomjs here https://github.com/pofider/phantom-html-to-pdf/blob/master/lib/scripts/conversionScriptPart.js#L14 Make sure it is called. If it is, try to search the phantomjs issues for a reference https://github.com/ariya/phantomjs/issues

This package is just a wrapper, so I cannot help you with this probably.