New issue
Advanced search Search tips

window.print dont fire window.onafterprint

Reported by hbd...@gmail.com, Dec 7

Issue description

UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36

Steps to reproduce the problem:
1. window.onafterprint = function(){console.log('after')};
2. window.print();
3. 

What is the expected behavior?
console write 'after'

What went wrong?
console dont write, onafterprint is not fired

Did this work before? Yes 70.0.3538.110

Chrome version: 71.0.3578.80  Channel: stable
OS Version: 10.0
Flash Version:
 
Cc: thestig@chromium.org pbomm...@chromium.org
Cc: haraken@chromium.org peria@chromium.org yukishiino@chromium.org
Components: -Blink Internals>Printing Blink>Bindings
Labels: -Pri-2 OS-Chrome OS-Linux OS-Mac Pri-1
Status: Untriaged (was: Unconfirmed)
onbeforeprint seems similarly broken. This bisects to https://chromium.googlesource.com/chromium/src/+log/2555486f..623c4e77 so it is very likely due to r597054.
Cc: gov...@chromium.org
Labels: RegressedIn-71 ReleaseBlock-Stable Target-71 M-71 FoundIn-71
Based on comment#2 this is a M71 regression hence tagging the bug as Stable blocker.
Labels: Target-72 M-72
Owner: yukishiino@chromium.org
Status: Started (was: Untriaged)
In general, onbeforeprint and onafterprint events are used for making web pages into a print-friendly layout (e.g. removing unnecessary banners, ads, etc.), and I'm afraid that these events would have major impacts on businesses (form print, receipt print, etc.).

I think that it's better to merge a fix into M71.

I've prepared a fix at:
https://chromium-review.googlesource.com/c/chromium/src/+/1368848

The fix is simple and pretty safe to merge.  I confirmed the fix with local build.
this is exactly my case, I have a business line application this bug caused a big problem in the impressions.

I would be very happy to release an update soon.
Can i get some more context regarding the issue, why it's an emergency, and why it's a stable blocker?  And why it was discovered so late in testing?  Timing is pretty bad for release plans
Re #5, Thank you yukishiino@. Could you pls merge the change to current canary branch 3633 once it lands so I can trigger new canary from same branch to make sure we get canary coverage? 

Is this bug applicable to Android as well?


Project Member

Comment 9 by bugdroid1@chromium.org, Dec 8

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/fa8fd965900a1ae66630aa9b36f1e837178f32e7

commit fa8fd965900a1ae66630aa9b36f1e837178f32e7
Author: Yuki Shiino <yukishiino@chromium.org>
Date: Sat Dec 08 16:24:39 2018

v8binding: Invoke on{before,after}print event listeners even when paused

This patch fixes a regression at https://crrev.com/c/1215512 ,
which doesn't run '{before,after}print' event listeners when one
of the related execution contexts is paused.  This is almost the
same fix as https://crrev.com/c/1333548 .

Another idea for fix is that Blink should pause an execution
context in a narrower range; after dispatching onbeforeprint event
and before dispatching onafterprint event.  However, the content/
layer has the control of printing and event dispatching, and it's
not easy to change such an overall design in a short term.
See also WebLocalFrame::Dispatch{Before,After}PrintEvent and its
implementations and call sites:
https://cs.chromium.org/chromium/src/third_party/blink/public/web/web_local_frame.h?rcl=92c06acc4c92805f4020ad1b12c537fa4ac122c3&l=670

With such a background, this patch allows exceptional invocations
not only for beforeunload event but also {before,after}print event.

TBR=haraken@chromium.org

Bug:  912966 
Change-Id: Id38be3ea61668a8e88274b95a4192837e469bd48
Reviewed-on: https://chromium-review.googlesource.com/c/1368848
Reviewed-by: Yuki Shiino <yukishiino@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#614972}
[modify] https://crrev.com/fa8fd965900a1ae66630aa9b36f1e837178f32e7/third_party/blink/renderer/bindings/core/v8/js_event_handler.cc
[modify] https://crrev.com/fa8fd965900a1ae66630aa9b36f1e837178f32e7/third_party/blink/renderer/bindings/core/v8/js_event_listener.cc

Project Member

Comment 10 by bugdroid1@chromium.org, Dec 8

Labels: merge-merged-3634
The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/dad0533b9a6bfda7b09b0bac2850b99ffea62fec

commit dad0533b9a6bfda7b09b0bac2850b99ffea62fec
Author: Yuki Shiino <yukishiino@chromium.org>
Date: Sat Dec 08 16:36:27 2018

v8binding: Invoke on{before,after}print event listeners even when paused

This patch fixes a regression at https://crrev.com/c/1215512 ,
which doesn't run '{before,after}print' event listeners when one
of the related execution contexts is paused.  This is almost the
same fix as https://crrev.com/c/1333548 .

Another idea for fix is that Blink should pause an execution
context in a narrower range; after dispatching onbeforeprint event
and before dispatching onafterprint event.  However, the content/
layer has the control of printing and event dispatching, and it's
not easy to change such an overall design in a short term.
See also WebLocalFrame::Dispatch{Before,After}PrintEvent and its
implementations and call sites:
https://cs.chromium.org/chromium/src/third_party/blink/public/web/web_local_frame.h?rcl=92c06acc4c92805f4020ad1b12c537fa4ac122c3&l=670

With such a background, this patch allows exceptional invocations
not only for beforeunload event but also {before,after}print event.

TBR=haraken@chromium.org

Bug:  912966 
Change-Id: Id38be3ea61668a8e88274b95a4192837e469bd48
Reviewed-on: https://chromium-review.googlesource.com/c/1368848
Reviewed-by: Yuki Shiino <yukishiino@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#614972}(cherry picked from commit fa8fd965900a1ae66630aa9b36f1e837178f32e7)
Reviewed-on: https://chromium-review.googlesource.com/c/1369209
Reviewed-by: Krishna Govind <govind@chromium.org>
Cr-Commit-Position: refs/branch-heads/3634@{#3}
Cr-Branched-From: 87ffab8656b43fd2a6b49c0bc62dc97bc26ebde5-refs/heads/master@{#614909}
[modify] https://crrev.com/dad0533b9a6bfda7b09b0bac2850b99ffea62fec/third_party/blink/renderer/bindings/core/v8/js_event_handler.cc
[modify] https://crrev.com/dad0533b9a6bfda7b09b0bac2850b99ffea62fec/third_party/blink/renderer/bindings/core/v8/js_event_listener.cc

I've merged the change listed at #9 to current canary branch 3634 and triggering new canary from same branch - https://chromium.googlesource.com/chromium/src.git/+/dad0533b9a6bfda7b09b0bac2850b99ffea62fec.
Re #c7: The issue is that 'onbeforeprint' and 'onafterprint' event dispatching doesn't work at all.  These events are usually used to make web pages into print-friendly layout so that printed papers do not include side menu, banners, redundant headers/footers, ads, etc.

I'm afraid that those who are doing "print web pages from Chrome" will be affected by the issue.  For example, application forms, receipts, etc. will be printed in unpleasant format/layout.  Those who're printing from Chrome in their daily business will be affected.  I personally think that it's worth stable blocking.


Re #c8: All platforms other than iOS are affected, including Android and Chrome OS, not limited to desktop.  I guess that it's not so rare nowadays to print web pages from Chrome on Android and Chrome OS.  I imagine that some merchants use Android tablets for their business and print web pages.

Re #c10: And thanks for the merge to Canary.

Cc: benmason@chromium.org
Labels: OS-Android
Adding OS=Android per comment #12 (+benmason@ Chrome on Android TPM).
Canary 73.0.3634.2 is currently building with this merge for Android, Desktop and CrOS.
NextAction: 2018-12-10
Canary #73.0.3634.2 went live which includes this merge. Pls update bug with canary result on Monday morning PT.
Thanks for the quick merge!

I believe that the fix is trivial and is a very low risk. i.e., it would be safe to merge to stable.


Labels: Merge-Approved-71
Thank you haraken@.

Approving merge to M71 branch 3578 based on comments #5, #12 and #16. 
Pls merge to M71 only after verifying on canary if change looks good. Thank you.
Labels: Merge-Approved-72
This will also need a merge to M72, so approving merge to M72 branch 3626.


Confirmed the fix on Canary on Mac: Version 73.0.3635.0 (Official Build) canary (64-bit)

(beforeprint, afterprint) x (event handler, event listener), all combinations work as expected.  I'll merge the fix to M71 and M72 tomorrow (Monday in JST).
Re #19: Sounds good, Thank you.
Any chance this can get merged to M71 asap so I'll have a version of chrome with the fix on Monday for Chrome OS?  Thanks
I'm trying to merge to M71 to unblock Stable RC cut for Chrome OS.
Sorry, I try to merge to M71 branch 3578 but unable to merge due to merge conflict. Getting below error:

An error occurred
Could not perform action: Cherry pick failed: merge conflict.


 yukishiino@, pls resolve merge conflict and then merge to M71. Thank you.
Pls merge you change to M72 branch 3626 ASAP so we can pick it up for next  Dev/Beta release, RC cut on Monday, 12/10 @ 1:00 PM PT. Thank you.
Project Member

Comment 25 by bugdroid1@chromium.org, Dec 10

Labels: -merge-approved-72 merge-merged-3626
The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/d6e7d74e2f4b33b0797dfc2183f6d345538971d9

commit d6e7d74e2f4b33b0797dfc2183f6d345538971d9
Author: Yuki Shiino <yukishiino@chromium.org>
Date: Mon Dec 10 06:38:10 2018

v8binding: Invoke on{before,after}print event listeners even when paused

This patch fixes a regression at https://crrev.com/c/1215512 ,
which doesn't run '{before,after}print' event listeners when one
of the related execution contexts is paused.  This is almost the
same fix as https://crrev.com/c/1333548 .

Another idea for fix is that Blink should pause an execution
context in a narrower range; after dispatching onbeforeprint event
and before dispatching onafterprint event.  However, the content/
layer has the control of printing and event dispatching, and it's
not easy to change such an overall design in a short term.
See also WebLocalFrame::Dispatch{Before,After}PrintEvent and its
implementations and call sites:
https://cs.chromium.org/chromium/src/third_party/blink/public/web/web_local_frame.h?rcl=92c06acc4c92805f4020ad1b12c537fa4ac122c3&l=670

With such a background, this patch allows exceptional invocations
not only for beforeunload event but also {before,after}print event.

TBR=haraken@chromium.org

Bug:  912966 
Change-Id: Id38be3ea61668a8e88274b95a4192837e469bd48
Reviewed-on: https://chromium-review.googlesource.com/c/1368848
Reviewed-by: Yuki Shiino <yukishiino@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#614972}(cherry picked from commit fa8fd965900a1ae66630aa9b36f1e837178f32e7)
Reviewed-on: https://chromium-review.googlesource.com/c/1369555
Cr-Commit-Position: refs/branch-heads/3626@{#172}
Cr-Branched-From: d897fb137fbaaa9355c0c93124cc048824eb1e65-refs/heads/master@{#612437}
[modify] https://crrev.com/d6e7d74e2f4b33b0797dfc2183f6d345538971d9/third_party/blink/renderer/bindings/core/v8/js_event_handler.cc
[modify] https://crrev.com/d6e7d74e2f4b33b0797dfc2183f6d345538971d9/third_party/blink/renderer/bindings/core/v8/js_event_listener.cc

Labels: -Merge-Approved-71 Merge-Merged-71-3578
The following revision refers to this bug: 
https://chromium.googlesource.com/chromium/src.git/+/4cf3d0904c332b3676790c7dc532bbaee5aea8e9

Commit: 4cf3d0904c332b3676790c7dc532bbaee5aea8e9
Author: yukishiino@chromium.org
Commiter: yukishiino@chromium.org
Date: 2018-12-10 07:59:37 +0000 UTC

v8binding: Invoke on{before,after}print event listeners even when paused

This patch fixes a regression at https://crrev.com/c/1215512 ,
which doesn't run '{before,after}print' event listeners when one
of the related execution contexts is paused.  This is almost the
same fix as https://crrev.com/c/1333548 .

Another idea for fix is that Blink should pause an execution
context in a narrower range; after dispatching onbeforeprint event
and before dispatching onafterprint event.  However, the content/
layer has the control of printing and event dispatching, and it's
not easy to change such an overall design in a short term.
See also WebLocalFrame::Dispatch{Before,After}PrintEvent and its
implementations and call sites:
https://cs.chromium.org/chromium/src/third_party/blink/public/web/web_local_frame.h?rcl=92c06acc4c92805f4020ad1b12c537fa4ac122c3&l=670

With such a background, this patch allows exceptional invocations
not only for beforeunload event but also {before,after}print event.

TBR=haraken@chromium.org

(cherry picked from commit fa8fd965900a1ae66630aa9b36f1e837178f32e7)

Bug:  912966 
Change-Id: Id38be3ea61668a8e88274b95a4192837e469bd48
Reviewed-on: https://chromium-review.googlesource.com/c/1368848
Reviewed-by: Yuki Shiino <yukishiino@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#614972}
Reviewed-on: https://chromium-review.googlesource.com/c/1369561
Cr-Commit-Position: refs/branch-heads/3578@{#886}
Cr-Branched-From: 4226ddf99103e493d7afb23a4c7902ee496108b6-refs/heads/master@{#599034}
Project Member

Comment 27 by bugdroid1@chromium.org, Dec 10

Labels: merge-merged-3578
The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/4cf3d0904c332b3676790c7dc532bbaee5aea8e9

commit 4cf3d0904c332b3676790c7dc532bbaee5aea8e9
Author: Yuki Shiino <yukishiino@chromium.org>
Date: Mon Dec 10 07:59:37 2018

v8binding: Invoke on{before,after}print event listeners even when paused

This patch fixes a regression at https://crrev.com/c/1215512 ,
which doesn't run '{before,after}print' event listeners when one
of the related execution contexts is paused.  This is almost the
same fix as https://crrev.com/c/1333548 .

Another idea for fix is that Blink should pause an execution
context in a narrower range; after dispatching onbeforeprint event
and before dispatching onafterprint event.  However, the content/
layer has the control of printing and event dispatching, and it's
not easy to change such an overall design in a short term.
See also WebLocalFrame::Dispatch{Before,After}PrintEvent and its
implementations and call sites:
https://cs.chromium.org/chromium/src/third_party/blink/public/web/web_local_frame.h?rcl=92c06acc4c92805f4020ad1b12c537fa4ac122c3&l=670

With such a background, this patch allows exceptional invocations
not only for beforeunload event but also {before,after}print event.

TBR=haraken@chromium.org

(cherry picked from commit fa8fd965900a1ae66630aa9b36f1e837178f32e7)

Bug:  912966 
Change-Id: Id38be3ea61668a8e88274b95a4192837e469bd48
Reviewed-on: https://chromium-review.googlesource.com/c/1368848
Reviewed-by: Yuki Shiino <yukishiino@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#614972}
Reviewed-on: https://chromium-review.googlesource.com/c/1369561
Cr-Commit-Position: refs/branch-heads/3578@{#886}
Cr-Branched-From: 4226ddf99103e493d7afb23a4c7902ee496108b6-refs/heads/master@{#599034}
[modify] https://crrev.com/4cf3d0904c332b3676790c7dc532bbaee5aea8e9/third_party/blink/renderer/bindings/core/v8/js_event_handler.cc
[modify] https://crrev.com/4cf3d0904c332b3676790c7dc532bbaee5aea8e9/third_party/blink/renderer/bindings/core/v8/js_event_listener.cc

Thank you yukishiino@.

Triggered new M71 build with this merge in for Android, Desktop and Chrome OS - version 71.0.3578.93 (currently building).
Labels: TE-Verified-M73 TE-Verified-73.0.3636.0
Able to reproduce this issue on Windows 10, Mac OS 10.13.6 and Ubuntu 17.10 on the reported version 71.0.3578.80 and the issue is fixed on the latest M-73 build 73.0.3636.0.

1. Launched Chrome and entered window.onafterprint = function(){console.log('after')}; and window.print(); in Devtools -> Console.
2. Could observe that 'after' is printed in the console.
Attached is the screen shot for reference.

Hence adding TE verified labels as the fix is working as intended.

Thanks..
912966-M73.PNG
49.8 KB View Download
The NextAction date has arrived: 2018-12-10
Status: Fixed (was: Started)
re #c28: M71 desktop builds finished.  The build results of 71.0.3578.93 are the same as ones of 71.0.3578.92 (previous one).  Some of content_browsertests and browser_tests are failing in the same way.  So, no difference between 93 and 92.

Chrome for Android is still in the middle of building.

re #c28: M71 Android builds finished successfully with all green.

Cc: tkent@chromium.org
I'll try to write a test for this, to make it harder to regress.
Labels: TE-Verified-M72 TE-Verified-72.0.3626.14
Able to reproduce this issue on Windows 10, Mac OS 10.13.6 and Ubuntu 17.10 on the reported version 71.0.3578.80 and the issue is fixed on the latest M-72 build 72.0.3626.14.

1. Launched Chrome and entered window.onafterprint = function(){console.log('after')}; and window.print(); in Devtools -> Console.
2. Could observe that 'after' is printed in the console.
Attached is the screen shot for reference.

Hence adding TE verified labels as the fix is working as intended.

Thanks..
//attaching screen shot for comment #35
912966-M72.PNG
49.4 KB View Download
Labels: TE-Verified-M71 TE-Verified-71.0.3578.95
Tested the issue on Windows 10, Mac OS 10.13.6, Ubuntu 17.10 and the issue is fixed on the latest M-71 build 71.0.3578.95.
Hence adding TE verified labels.

Thanks..
 Issue 914019  has been merged into this issue.
Project Member

Comment 39 by bugdroid1@chromium.org, Dec 11

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/39e5d59018f0fb802cff93a5d9793c0905b9b497

commit 39e5d59018f0fb802cff93a5d9793c0905b9b497
Author: Lei Zhang <thestig@chromium.org>
Date: Tue Dec 11 19:31:22 2018

Add more PrintRenderFrameHelperTests.

- PrintRenderFrameHelperTest.WindowPrintBeforePrintAfterPrint covers the
  regression in  bug 912966  without Print Preview.
- PrintRenderFrameHelperPreviewTest.WindowPrintBeforePrintAfterPrint
  covers the regression in  bug 912966  with Print Preview.
- PrintRenderFrameHelperPreviewTest.BasicBeforePrintAfterPrint is the
  equivalent to PrintRenderFrameHelperTest.BasicBeforePrintAfterPrint,
  but for Print Preview.
- Merge common code to avoid repeats.

BUG= 912966 

Change-Id: I80b0ef718e4f06e2e1bd858bd1c2a39028d4a6ec
Reviewed-on: https://chromium-review.googlesource.com/c/1371211
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#615624}
[modify] https://crrev.com/39e5d59018f0fb802cff93a5d9793c0905b9b497/components/printing/test/print_render_frame_helper_browsertest.cc

Cc: vamshi.kommuri@chromium.org
 Issue 914018  has been merged into this issue.
Good news: 71.0.3578.98 is now available with the fix on Chrome Stable. You can force an update by visiting chrome://chrome. Thank you.
Labels: Merge-Merged-72-3626
The following revision refers to this bug: 
https://chromium.googlesource.com/chromium/src.git/+/d6e7d74e2f4b33b0797dfc2183f6d345538971d9

Commit: d6e7d74e2f4b33b0797dfc2183f6d345538971d9
Author: yukishiino@chromium.org
Commiter: yukishiino@chromium.org
Date: 2018-12-10 06:38:10 +0000 UTC

v8binding: Invoke on{before,after}print event listeners even when paused

This patch fixes a regression at https://crrev.com/c/1215512 ,
which doesn't run '{before,after}print' event listeners when one
of the related execution contexts is paused.  This is almost the
same fix as https://crrev.com/c/1333548 .

Another idea for fix is that Blink should pause an execution
context in a narrower range; after dispatching onbeforeprint event
and before dispatching onafterprint event.  However, the content/
layer has the control of printing and event dispatching, and it's
not easy to change such an overall design in a short term.
See also WebLocalFrame::Dispatch{Before,After}PrintEvent and its
implementations and call sites:
https://cs.chromium.org/chromium/src/third_party/blink/public/web/web_local_frame.h?rcl=92c06acc4c92805f4020ad1b12c537fa4ac122c3&l=670

With such a background, this patch allows exceptional invocations
not only for beforeunload event but also {before,after}print event.

TBR=haraken@chromium.org

Bug:  912966 
Change-Id: Id38be3ea61668a8e88274b95a4192837e469bd48
Reviewed-on: https://chromium-review.googlesource.com/c/1368848
Reviewed-by: Yuki Shiino <yukishiino@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#614972}(cherry picked from commit fa8fd965900a1ae66630aa9b36f1e837178f32e7)
Reviewed-on: https://chromium-review.googlesource.com/c/1369555
Cr-Commit-Position: refs/branch-heads/3626@{#172}
Cr-Branched-From: d897fb137fbaaa9355c0c93124cc048824eb1e65-refs/heads/master@{#612437}
Labels: Postmortem-Followup

Sign in to add a comment