Project: chromium Issues People Development process History Sign in
New issue
Advanced search Search tips
Issue 218205 Support for `afterprint` and `beforeprint` events
Starred by 39 users Reported by alexan...@skovik.com, Mar 18 2013 Back to list
Status: Available
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 3
Type: Feature



Sign in to add a comment
UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22

Steps to reproduce the problem:
See below

What is the expected behavior?
See below

What went wrong?
Support for `afterprint` and `beforeprint` events. These event exists in Firefox and Internet Explorer.

MATCHMEDIA
Matchmedia is similar, but not built for the same purpose (the purpose of matchmedia is to have javascript behave different when printing a page).

One problem is that it may fire multiple times.
Another is that it will fire even though the page wasn't printed (when canceling the print dialog).

For example, when using analytics to track how often a page is printed `afterprint` is great, and `matchmedia` isn't of much use. I'm sure there are other usecases too.

REFERENCES
# http://www.w3.org/TR/html5/webappapis.html#printing
# https://developer.mozilla.org/en-US/docs/DOM/window.onafterprint
# https://developer.mozilla.org/en-US/docs/DOM/window.onbeforeprint
# http://www.w3.org/TR/html-markup/body.html#body.attrs.onafterprint

Did this work before? No 

Chrome version: 25.0.1364.172  Channel: stable
OS Version: OS X 10.8.2
 
Project Member Comment 1 by bugdroid1@chromium.org, Apr 5 2013
Labels: Cr-Blink
Project Member Comment 2 by bugdroid1@chromium.org, Apr 6 2013
Labels: -Cr-Content-JavaScript Cr-Blink-JavaScript
Comment 3 by jrumer...@gmail.com, Oct 20 2014
I know this is old, but the workarounds for no print events are annoying and unreliable compared to dedicated events. Moreover, the workarounds recently broke (Chrome 38+ - covered in other bugs) so this has some attention. So if anybody from Chrome team is watching here's +1 for dedicated events. :)
Comment 4 by Deleted ...@, Oct 30 2014
I was surprised, Google yet to incorporate these events in Chrome! Print events are pretty useful though.
There's a workaround of using matchMedia. 
Details here: http://tjvantoll.com/2012/06/15/detecting-print-requests-with-javascript/
Comment 6 by mudc...@gmail.com, Oct 31 2014
The matchMedia workaround doesn't work as it once did. The pseudo "onafterprint" equivalent fires before the print job is sent, and then nothing is fired after the print job has been triggered.
Labels: -Cr-Blink-JavaScript Cr-Blink-DOM
Issue 422883 has been merged into this issue.
Cc: dominicc@chromium.org
Labels: -Pri-2 -Type-Bug -OS-Mac -Cr-Blink Pri-3 Type-Feature OS-All
Status: Available
Print media queries should work now; they were fixed in Issue 401179.

That said, I believe onbeforeprint, onafterprint are: in the HTML5 spec; supported by Firefox and IE; and have garnered ~30 stars or so. Blink should consider implementing them.
Project Member Comment 10 by bugdroid1@chromium.org, Nov 7 2015
The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/eaf8d002d734bfcb967527924e0ea9ed5328e2c1

commit eaf8d002d734bfcb967527924e0ea9ed5328e2c1
Author: jsbell <jsbell@chromium.org>
Date: Sat Nov 07 05:46:26 2015

update-w3c-deps import using blink 83a52878976eaffc8753993a7689c9c178664fba:

imported csswg-test@abaf54a8e7ec8969c9bd8e7b63fe5c1c759eedfd
imported web-platform-tests@f581ba0215965bb4dc255dd1f4ae5857f923f161

csswg-test/css-shapes-1/shape-outside/values/shape-outside-*
* 7 modified

csswg-test/css-writing-modes-3/line-box-height-vlr-*
* 6 modified

web-platform-tests/IndexedDB/
* 5 added
* remove 5 tests in storage/indexeddb that were upstreamed

web-platform-tests/html/obsolete/requirements-for-implementations/other-elements-attributes-and-apis/script-IDL-event-htmlfor.html
* now passes, -expected.txt removed

web-platform-tests/html/webappapis/scripting/events/event-handler-attributes-body-window.html
* new test, fails some cases due to crbug.com/218205 so -expected.txt added
* test output is horrid, filed https://github.com/w3c/web-platform-tests/pull/2310

R=kojii@chromium.org
BUG=218205

Review URL: https://codereview.chromium.org/1419013007

Cr-Commit-Position: refs/heads/master@{#358517}

[modify] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/csswg-test/css-shapes-1/shape-outside/values/shape-outside-circle-010.html
[modify] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/csswg-test/css-shapes-1/shape-outside/values/shape-outside-circle-011.html
[modify] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/csswg-test/css-shapes-1/shape-outside/values/shape-outside-ellipse-010.html
[modify] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/csswg-test/css-shapes-1/shape-outside/values/shape-outside-ellipse-011.html
[modify] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/csswg-test/css-shapes-1/shape-outside/values/shape-outside-inset-008.html
[modify] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/csswg-test/css-shapes-1/shape-outside/values/shape-outside-inset-009.html
[modify] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/csswg-test/css-shapes-1/shape-outside/values/shape-outside-polygon-006.html
[modify] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/csswg-test/css-writing-modes-3/line-box-height-vlr-003-expected.xht
[modify] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/csswg-test/css-writing-modes-3/line-box-height-vlr-003.xht
[modify] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/csswg-test/css-writing-modes-3/line-box-height-vlr-005-expected.xht
[modify] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/csswg-test/css-writing-modes-3/line-box-height-vlr-005.xht
[modify] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/csswg-test/css-writing-modes-3/line-box-height-vlr-007-expected.xht
[modify] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/csswg-test/css-writing-modes-3/line-box-height-vlr-007.xht
[modify] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/csswg-test/css-writing-modes-3/line-box-height-vlr-009-expected.xht
[modify] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/csswg-test/css-writing-modes-3/line-box-height-vlr-009.xht
[modify] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/csswg-test/css-writing-modes-3/line-box-height-vlr-011-expected.xht
[modify] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/csswg-test/css-writing-modes-3/line-box-height-vlr-011.xht
[modify] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/csswg-test/css-writing-modes-3/line-box-height-vlr-013-expected.xht
[modify] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/csswg-test/css-writing-modes-3/line-box-height-vlr-013.xht
[rename] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/web-platform-tests/IndexedDB/idbindex_getAll.html
[rename] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/web-platform-tests/IndexedDB/idbindex_getAllKeys.html
[rename] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/web-platform-tests/IndexedDB/idbobjectstore_getAll.html
[rename] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/web-platform-tests/IndexedDB/idbobjectstore_getAllKeys.html
[add] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/web-platform-tests/IndexedDB/idbtransaction_objectStoreNames.html
[delete] http://crrev.com/722b2e4252160796ae85bd3cf6445b47edae8a51/third_party/WebKit/LayoutTests/imported/web-platform-tests/html/obsolete/requirements-for-implementations/other-elements-attributes-and-apis/script-IDL-event-htmlfor-expected.txt
[modify] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/web-platform-tests/html/obsolete/requirements-for-implementations/other-elements-attributes-and-apis/script-IDL-event-htmlfor.html
[add] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/web-platform-tests/html/webappapis/scripting/events/event-handler-attributes-body-window-expected.txt
[add] http://crrev.com/eaf8d002d734bfcb967527924e0ea9ed5328e2c1/third_party/WebKit/LayoutTests/imported/web-platform-tests/html/webappapis/scripting/events/event-handler-attributes-body-window.html
[delete] http://crrev.com/722b2e4252160796ae85bd3cf6445b47edae8a51/third_party/WebKit/LayoutTests/storage/indexeddb/idbtransaction_objectstorenames.html

Components: Internals>Printing
Labels: Hotlist-Interop
Comment 12 by tkent@chromium.org, Apr 18 2016
Components: -Blink>DOM Blink>HTML
Labels: Needs-BlinkIntent
Comment 14 by rbyers@chromium.org, Today (16 hours ago)
Anyone have any idea how much work this would be?  Being in Edge and Gecko certainly makes it attractive as something we should consider doing in Blink.

Some discussion on twitter: https://twitter.com/develoger/status/857877218525138945
Sign in to add a comment