Can we use screen media when printing web page using headless chrome

405 views
Skip to first unread message

prakashvis...@gmail.com

unread,
May 22, 2018, 8:34:34 AM5/22/18
to headless-dev
Hi Everyone,

I'm converting web page to PDF using prebuilt chrome headless browser in command line, but it always uses print media type to render the webpages in PDF document. But I need to print the webpages with screen media type. Is there any option to enable or disable print/screen media type when generating PDF. 

Regards,
Prakash V

Eric Seckler

unread,
May 22, 2018, 8:37:39 AM5/22/18
to prakashvis...@gmail.com, headless-dev
You can use Emulation.setEmulatedMedia to achieve this, but note that printing with screen media type is not an officially supported configuration - you may see some incorrectly rendered content when doing this.

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev...@chromium.org.
To post to this group, send email to headle...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/headless-dev/9490cf66-68f8-4905-b9a1-65bff7442522%40chromium.org.

prakashvis...@gmail.com

unread,
May 22, 2018, 8:44:15 AM5/22/18
to headless-dev, prakashvis...@gmail.com
Hi Eric,

Thanks for your update.
I'm using pre built headless to print the PDF, how do I set the Emulation.setEmulatedMedia in command line.

Eric Seckler

unread,
May 22, 2018, 8:46:50 AM5/22/18
to prakashvis...@gmail.com, headless-dev
There is no way to set this from the command line, sorry. You'll have to use the DevTools protocol (e.g. using --remote-debugging-port=9222 or --remote-debugging-pipe). Puppeteer might be an alternative, too, if you don't want to write your own DevTools protocol client implementation.

teo.et...@gmail.com

unread,
Feb 21, 2019, 6:44:06 AM2/21/19
to headless-dev, prakashvis...@gmail.com
Definitely there should be a option to disable the screen media type to be print. A lot of pages has unoptimised print.css that just destroy the page.
A simple parameter would to the job.
Reply all
Reply to author
Forward
0 new messages