ChatGPT解决这个技术问题 Extra ChatGPT

Using Chrome's Element Inspector in Print Preview Mode?

I am working on developing a website and need to work on the print view. Typically when I have layout issues I use Chrome's Element Inspector. However this does not exist in print preview mode.

Is there a Chrome plugin or some other way to change your viewing medium within chrome itself, to view a page as a printer would? I suppose it doesn't have a be a Chrome specific solution, but that is my primary browser so it would be nice to have an in-browser solution.

Right now I'm focused just on the print preview medium, but it would be ideal to be able to change to any of the supported media types (i.e. all/braille/embossed/handheld/print/projection/screen/speech/tty/tv).


C
Community

Note: This answer covers several versions of Chrome, scroll to see v52, v48, v46, v43 and v42 each with their updated changes.

Chrome v52+:

Open the Developer Tools (Windows: F12 or Ctrl+Shift+I, Mac: Cmd+Opt+I)

Click the Customize and control DevTools hamburger menu button and choose More tools > Rendering settings (or Rendering in newer versions).

Check the Emulate print media checkbox at the Rendering tab and select the Print media type.

https://i.stack.imgur.com/7BCx7.png

Chrome v48+ (Thanks Alex for noticing):

Open the Developer Tools (CTRLSHIFTI or F12)

Click the Toggle device mode button in the left top corner (CTRLSHIFTM).

Make sure the console is shown by clicking Show console in menu at (1) (ESC key toggles the console if Developer Toolbar has focus).

Check Emulate print media at the rendering tab which can be opened by selecting Rendering in menu at (2).

https://i.stack.imgur.com/ClmyX.png

Chrome v46+:

Open the Developer Tools (CTRLSHIFTI or F12)

Click the Toggle device mode button in the left top corner (1).

Make sure the console is shown by clicking the menu button (2) > Show console (3) or pressing the ESC key to toggle the console (only works when Developer Toolbar has the focus).

Open the Emulation (4) > Media (5) tabs, check CSS media and select print (3).

https://i.stack.imgur.com/Gyoil.png

Chrome v43+:

The drawer icon at step 2 has changed.

https://i.stack.imgur.com/jT8Wz.png

Chrome v42:

Open the Developer Tools (CTRLSHIFTI or F12)

Click the Toggle device mode button in the left top corner (1).

Make sure the drawer is shown by clicking the Show drawer button (2) or pressing the ESC key to toggle the drawer.

Under Emulation > Media check CSS media and select print (3).

https://i.stack.imgur.com/yU62w.png


I can confirm this so I made this the approved answer. I'm not sure why they keep insisting on moving it every few releases.
Found it in Chrome 48, but they moved it again: Go to "rendering" in the Drawer, check "Emulate print media".
These frequent changes are the dumbest thing I've seen to come out of google as of yet! Such a waste of my time.
Unfortunately this does not always emulate the same thing that print preview shows, so not so great for debugging. It is good for seeing what general layout and styles are though.
This 'print' emulator is completely useless. It does not properly emulate the page, as in what you see in the browser will be nothing like what you see in the print preview. Does anyone have a working solution?
K
K.Dᴀᴠɪs

Changed in Chrome 32 35+

(In Chrome 35+ the "Emulation" tab is present by default. Also, the console is available from any primary tab.)

In DevTools, go to settings-> Overrides enable "Show Emulation view in console drawer" Close settings, go to 'Elements' tab Hit Esc to bring up console Choose tab "Emulation", click "Screen" Scroll down to "CSS Media", select "print"

This option is not (yet?) available in the console tab.

https://i.stack.imgur.com/2itUb.jpg


To reflect this update, I've gone ahead and marked this as the correct answer now.
The Overrides tab is no longer there in Chrome 36 (I don't know when that was changed). The Emulation tab is present by default.
Is it just me or is the CSS media option gone in Chrome 36? Now can only select based on specific mobile device. UPDATE: doh. As per above instructions, literally have to click on "Screen". Not immediately obvious that it's clickable.
The only problem I have found, now that I am using it, is that it isn't actually what Chrome prints out. This is extremely evident with Bootstrap 3.x where the media will use grid-md whereas the print preview uses grid-sm
Chrome 39 this is under "media". you must enable the device emulation by clicking on the little phone icon on the left of the devtools top bar first, and then click the 3 dots in the top right of the device emulator.
A
Alexander Pavlov

Since Chrome 32 you have the CSS media option in the Screen section of the drawer Emulation tab.

Just enable it, select print as the target media type, and - behold - your page is rendered [almost] the way it will be printed.

https://i.imgur.com/0dW6y8X.png

Use Esc to bring up the drawer if it's not visible.


I was hoping it'd be simpler than this, but I suppose it will have to do for now. It would be nice if this eventually was built into one of the tools automatically.
When I get the chance, I'll have to give that a try. I may just stick with @Jon-YYC's method until then.
Im using version 28 on mac and do not see this option... anyone else have this problem?
@AaronHill I am using version 28 on a Mac and have no problem with it. Although perhaps you didn't actually get into the settings dialog. You can find this by clicking the gear icon in the bottom right hand corner of Element Inspector.
This answer is now out-of-date.
K
K.Dᴀᴠɪs

As of Chrome 48 (and perhaps a few versions earlier), the function seems to have moved yet again:

The first few steps are unchanged:

Press F12 to bring up the developer tools Press ESC to open the console

According to the previous answers, the setting could then be found under the "Emulation" tab. As shown in the images below, it has now been moved to the "Rendering" tab, which can be brought up by clicking on the three dots to the left of the "Console" tab.

https://i.stack.imgur.com/96yVn.png

https://i.stack.imgur.com/pgRuP.png


C
Community

Please see This article

https://i.stack.imgur.com/CHdfg.png

Then goto the "overrides" tab

https://i.stack.imgur.com/06AKS.png


This answer is now out-of-date.
K
K.Dᴀᴠɪs

As of Chrome 48+, you can access the print preview via the following steps:

Open dev tools – Ctrl/Cmd + Shift + I or right click on the page and choose 'Inspect'. Hit Esc to open the additional drawer. If 'Rendering' isn't already being show, click the 3 dot kebab and choose 'rendering'. Check the 'Emulate print media' checkbox.

From there Chrome will show you a print version of your page and you can inspect element and troubleshoot like you would the browser version.

https://i.stack.imgur.com/xKbZ2.jpg


Do you have a source for an updated DevTools Instructions? I can figure most of them out, but I was searching all over for this & I feel like there are a lot of helpful new features that are hiding from me.
The best source I found for general dev tools info is developers.google.com/web/tools/chrome-devtools/?hl=en. I also really enjoyed watching the updates for the latest version in this video: youtube.com/watch?v=dJR-n8szgBc.
K
Kariem

With shortcuts available, the quickest way is to

Open the Developer Tools Windows: F12 or Ctrl+Shift+I Mac: Cmd+Opt+I Open the Command Menu Windows: Ctrl+Shift+P Mac: Cmd+Shift+P Type print and select Emulate CSS print media type from the context menu

Looking at the excellent and currently most-upvoted answer by lmeurs, I think this solution might also remain stable over time.


Doing the same thing via DevTools GUI: Menu -> More tools -> Rendering. See "Rendering tab" and scroll down to "Emulate CSS media type" pull-down.
R
Rosdi Kasim

If you are debugging your CSS using Print As PDF in Google Chrome and your CSS element background colors are not showing, then make sure the 'Background graphics' checkbox is ticked. I spent almost 30 minutes debugging my CSS and wondering what is causing my CSS background being ignored.

https://i.stack.imgur.com/OJ93g.png


u
user2182349

Under Chrome v51 on a Mac, I found the rendering settings by clicking in the upper right corner, choosing More tools > Rendering settings and checking the Emulate media button in the options offered at the bottom of the window.

https://i.stack.imgur.com/Qd3bl.png

Thank you to all the other posters that led me to this, and credit to those that provided the answer without the images.


Whether I select print or screen in "emulate media", it still prints with the print stylesheet. I ended up using a full page screenshot extension instead. chrome.google.com/webstore/detail/full-page-screen-capture/…
a
ascripter

Chrome v67 (mac):

Hold down Cmd+opt+j to open dev tools click the ... on the righthand side, and choose: More Tools >> Rendering When the Rendering window shows up at the bottom of the screen, Emulate CSS Media section and choose: "Screen" from the dropdown. Go to "File >> Print" and you should see the view you want printing.

Images of the above description for Chrome v67 on a mac:

Where to find the Rendering tab: Click the ... on the righthand side, and choose: More Tools >> Rendering

https://i.stack.imgur.com/QWY7k.png

How to get the "screen" view to print: When the Rendering window shows up at the bottom of the screen, Emulate CSS Media section and choose: "Screen" from the dropdown.

https://i.stack.imgur.com/lBmTg.png

Hope it helps.


B
Ben Richter

Chrome v50:

Way 1:

Menu > More Tools > Rendering settings (see image) Down: Rendering Tab > Emulate media "print"

Way 2:

Open Console [esc] Console Menu > rendering