phantomjs icon indicating copy to clipboard operation
phantomjs copied to clipboard

Support for defining media type when rendering pages

Open nixx opened this issue 14 years ago • 27 comments

[email protected] commented:

When doing a print of a page using render, there is no way of defining the media type used. Today, it will use print, but it would be handy to be able to define the media type in use.

There is an open issue on QTWebKit on this: https://bugs.webkit.org/show_bug.cgi?id=25866

Today "print" is used when printing to a PDF which is not the wanted type when making screenshots from web pages for testing and documentation purposes.

Disclaimer: This issue was migrated on 2013-03-15 from the project's former issue tracker on Google Code, Issue #374. :star2:   5 people had starred this issue at the time of migration.

nixx avatar Feb 07 '12 18:02 nixx

This is causing me problems as well. As far as I can tell it is not limited to just pdf output. As a tool for capturing screenshots, it would seem sensible to allow phantomjs to capture what gets rendered on an actual screen by specifying the media type.

MarkMT avatar Aug 30 '14 12:08 MarkMT

Any update on this?

Petah avatar Oct 07 '14 00:10 Petah

This is causing many problems. There should be a way to choose the media type when rendering.

pankajan avatar Nov 20 '14 10:11 pankajan

(+1) on this as well

andineck avatar Nov 27 '14 21:11 andineck

:+1:

qfox avatar Dec 04 '14 16:12 qfox

(+1) got the same issue

kopax avatar Dec 16 '14 14:12 kopax

+1

dinatih avatar Feb 13 '15 02:02 dinatih

+1

davidsonnabend avatar Feb 17 '15 14:02 davidsonnabend

+1

jakgra avatar Feb 22 '15 12:02 jakgra

note to self: "When you use the pdf function the @media print is being used." -- https://github.com/ariya/phantomjs/issues/10669

neofreko avatar Mar 26 '15 23:03 neofreko

To resolve this issue for me temporarily (before they decide to change webkit (the request is pending)) I have created a small utility to take pdf snapshots with @media screen . It is not a good solution as it forces you to use a modified version of phantomjs. But still, feel free to use it (of course you can also use it without the gui). Here is the website: https://github.com/jakgra/website-pdf-snapshot-taker

jakgra avatar Mar 30 '15 05:03 jakgra

+1

flxw avatar Jun 09 '15 12:06 flxw

Thanks for the pointer @jakgra !

I was running into this problem too, especially on sites using bootstrap, and wkhtmltopdf did not seem to do the job either. So i rebuilt phantomjs on windows as per @jakgra instructions, and ended up making a UI frontent for taking some screenshots.

If anyone needs the modified windows build of phantomjs with @media print disabled you can grab it from the /dist folder here https://github.com/itechnology/PhantomUI

What if PhantomJS just patched it themselves (instead of waiting for webkit) and give us a switch to be able to choose how to capture pages, since i suppose many ppl will surely want to capture the various @media types for testing purposes ?

robert-hoffmann avatar Jun 12 '15 15:06 robert-hoffmann

+1 for this

kawing-chiu avatar Jul 27 '15 09:07 kawing-chiu

@ariya Would you accept a patch that changes the included qt code?

jkenn99 avatar Sep 18 '15 23:09 jkenn99

+1. After days of trying to track down the issues related to my code I FINALLY found this as the source of my problem. Trying to use webshot (wrapper for screenshots on server rendered screens using phantomjs) via meteor and sure enough I'm trying to use Bootstrap but coming up with SIGNIFICANTLY different output than intended. This simple option would REALLY be beneficial for me. Please consider patching in phantomjs (and not waiting for webkit to change) given this issue has been open for years now.

jonnymd avatar Mar 28 '16 02:03 jonnymd

@ariya Is there any update on this?

What is required to get this implemented? How can we help?

willemmulder avatar Jun 30 '16 10:06 willemmulder

Came here as I had the same problem trying to take pdf screenshots of my website.

Just want to point out that you can programmatically change media queries target ('screen' 'to 'all') and activate media all for <link>s without touching the original CSS.

see the following snippet (activateAllStylesheets()):

https://gist.github.com/gunzip/0ef59bab2d304dc597513413f2bd9305

it works only if jQuery is included in the web page but it's easy to convert into vanilla js.

gunzip avatar Dec 14 '16 14:12 gunzip

+1. A CSS media switch would really be useful, rather than dynamically modifying the website CSS. I'm surprised that this option isn't available.

michaelfranzl avatar Jan 21 '17 19:01 michaelfranzl

+1

SHND avatar Apr 06 '17 23:04 SHND