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

'#' in data URI body might break the PDF #90

Open mmrko opened 5 years ago

mmrko commented 5 years ago

First, thanks for the awesome repo! We've cherry-picked on it quite extensively @TimmaLabs.

Over the New Year we came upon an issue (which other users might now be running into as well) where our PDFs would suddenly start breaking after a deploy. Then we ran into this in the logs:

2019-01-01T14:31:05.502Z - info: [render-core.js] PAGE LOG: 
_type=warning, _text=Using unescaped '#' characters in a data URI body is deprecated
and will be removed in M71, around December 2018. Please use '%23' instead.
See https://www.chromestatus.com/features/5656049583390720 for more details., _args=[]

A simple fix was to escape all # characters before appending the HTML to the data URI (in render-core.js:90):

logger.info('Set HTML ..');
+ // https://www.chromestatus.com/features/5656049583390720
+ opts.html = opts.html.replace(/#/g, '%23');
// https://github.com/GoogleChrome/puppeteer/issues/
await page.goto(`data:text/html;charset=UTF-8,${opts.html}`, opts.goto);

Didn't want to PR this change yet as I'm not sure whether this is a common issue or not.

kimmobrunfeldt commented 5 years ago

Thanks for the report! I would happily merge this as PR, as it seems to be the de-facto way to do it in Chrome based on the warning.