alvarcarto / url-to-pdf-api

Web page PDF/PNG rendering done right. Self-hosted service for rendering receipts, invoices, or any content.
MIT License
7.01k stars 774 forks source link

Adds ability to pass cookies #21

Closed steakunderscore closed 6 years ago

steakunderscore commented 6 years ago

This implements #9.

Tested using ARC

Link to puppeteer setCookie docs

steakunderscore commented 6 years ago

Few, that was harder than I expected. Just added minor change to the readme, and worked out how to manually test using get. It works! 😄

I tested using the following. I had another web app running on localhost:3000, which required a cookie to be authenticated:

var qs = require('qs');
cookies = [
{
    "domain": "localhost",
    "httpOnly": true,
    "name": "_montreal_rb_session",
    "path": "/",
    "secure": false,
    "value": "ci9pblVvQ2RRNnVrVkk4SkVuSFRsVHY2OVlOSHBzSTZ0YnBGTXdIMnNRUk54SVlDUkoyMVUzUDdFRDh0aUFGOUdrb0FlODdGMk44WW9jTDdTalBWdFd3d0QySFcxY0xSeE5pMmNKM25WSTJ4ZmRnL3RWa0w5Qk9XSnFYTDk0a2dxTGRTMytJWlJrSDFmVVI2bVBXUllsdHNud2pwL1E3ZmhhN0VpdkJGQ0x3bkg1cW0xK1ZsN3U0Z1VCODIxRWNUTWtTR0NEbncxcnh1QnBBNlZpVGQzR040cXRmL05rWFArN2s4UStxTkFqWT0tLWswTS8vZHlXVHRiU2FtWXdtcmZpTGc9PQ%3D%3D--9d05bdb6babe3326f723c0c1ec6571e296a7d6cd"
}
]
"http://localhost:9000/api/render?" + decodeURIComponent(qs.stringify({url: "http://localhost:3000/", "viewport.width": 2048, "pdf.scale": 0.5, cookies: cookies}))
kimmobrunfeldt commented 6 years ago

This has now conflicts after merging another PR. Otherwise looks good!

kimmobrunfeldt commented 6 years ago

Thank you!