Bug 24061 - Print List (opac-shelves.pl) broken in Chrome
Summary: Print List (opac-shelves.pl) broken in Chrome
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: OPAC (show other bugs)
Version: Main
Hardware: All All
: P5 - low minor
Assignee: Jonathan Druart
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-11-18 17:07 UTC by Lucas Gass (lukeg)
Modified: 2021-12-13 21:09 UTC (History)
7 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
20.05.00, 19.11.03, 19.05.08, 18.11.14
Circulation function:


Attachments
Bug 24061: change setTimeout in opac-shelves.tt (846 bytes, patch)
2019-11-19 22:59 UTC, Lucas Gass (lukeg)
Details | Diff | Splinter Review
[ALTERNATIVE-PATCH] Bug 24061: Close the window after the page has been printed (914 bytes, patch)
2019-11-20 08:20 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 24061: Close the window after the page has been printed (969 bytes, patch)
2019-11-20 17:44 UTC, Lucas Gass (lukeg)
Details | Diff | Splinter Review
Bug 24061: Close the window after the page has been printed (919 bytes, patch)
2019-11-21 15:31 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 24061: close after timeout if onafterprint no supported (960 bytes, patch)
2019-11-22 09:17 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 24061: close after timeout if onafterprint no supported (1016 bytes, patch)
2020-01-07 21:59 UTC, Gabriel DeCarufel
Details | Diff | Splinter Review
Bug 24061: Close the window after the page has been printed (976 bytes, patch)
2020-01-20 06:52 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 24061: Close after timeout if onafterprint no supported (1.05 KB, patch)
2020-01-20 06:52 UTC, Katrin Fischer
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Lucas Gass (lukeg) 2019-11-18 17:07:39 UTC
In Chrome if you try to print a public list from the OPAC the new tab is immediately closed by Chrome.

TO TEST:
-set up a new public list with a few items
-go to the OPAC and view that list.
-Click 'Print List' in Chrome.
-The tab opens but immediately closes itself.
Comment 1 Jonathan Druart 2019-11-19 08:29:29 UTC
Which versions?
Looks ok for me on Chrome 60.0.3112.113 and Chromium 73.0.3683.75
Comment 2 Katrin Fischer 2019-11-19 09:12:29 UTC
Could this be related to the behavior fixed by bug 23680?

I've tested too, but couldn't reproduce the problem:

Google Chrome
Version 70.0.3538.77 (Official Build) (64-bit)
in Ubuntu
Comment 3 Katrin Fischer 2019-11-19 09:16:01 UTC
I think the print code was changed at some point - which version are you looking at? I tested on master.
Comment 4 Lucas Gass (lukeg) 2019-11-19 17:26:10 UTC
This is happening to me on master in Chrome 78.0.3904.97
Comment 5 Liz Rea 2019-11-19 17:31:43 UTC
Same results for me - go to print, window opens and immediately closes.
Comment 6 Lucas Gass (lukeg) 2019-11-19 22:57:43 UTC
I think this is because the setTimeout() is too quick for Chrome. (1ms)

967     [% IF print %]
968         window.print();
969         setTimeout('window.close()', 1);
970     [% END %]
Comment 7 Lucas Gass (lukeg) 2019-11-19 22:59:52 UTC
Created attachment 95589 [details] [review]
Bug 24061: change setTimeout in opac-shelves.tt

TEST PLAN:
-set up a new public list with a few items
-go to the OPAC and view that list.
-Click 'Print List' in Chrome.
-The tab opens but immediately closes itself.
-Apply patch and try again   
-Now you can print!
Comment 8 Jonathan Druart 2019-11-20 08:20:33 UTC
Created attachment 95591 [details] [review]
[ALTERNATIVE-PATCH] Bug 24061: Close the window after the page has been printed
Comment 9 Jonathan Druart 2019-11-20 08:21:46 UTC
Hi Lucas, Stackoverflow suggests to close the window after it has been print, ie. it takes back the focus. The solution sounds quite good to me.

Could you try it?
Comment 10 Lucas Gass (lukeg) 2019-11-20 17:44:18 UTC
Created attachment 95623 [details] [review]
Bug 24061: Close the window after the page has been printed

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 11 Lucas Gass (lukeg) 2019-11-20 17:45:58 UTC
Jonathan,

Yes this seems better to me and works perfect. Obsoleted my patch and SO'd on yours. Thanks so much.
Comment 12 Marcel de Rooy 2019-11-21 07:07:28 UTC
If you cancel the print action, the extra tab is not closed in Firefox. In that sense increasing the timeout worked better.
Comment 13 Jonathan Druart 2019-11-21 11:06:14 UTC
(In reply to Marcel de Rooy from comment #12)
> If you cancel the print action, the extra tab is not closed in Firefox. In
> that sense increasing the timeout worked better.

It works for me, could you retry?
Comment 14 Marcel de Rooy 2019-11-21 11:10:37 UTC
(In reply to Jonathan Druart from comment #13)
> (In reply to Marcel de Rooy from comment #12)
> > If you cancel the print action, the extra tab is not closed in Firefox. In
> > that sense increasing the timeout worked better.
> 
> It works for me, could you retry?

Retried although nothing changed. And still does not close the additional tab in FF when canceling the print dialog. If I confirm printing, it does close.
Comment 15 Jonathan Druart 2019-11-21 11:52:04 UTC
Which versions of Firefox are you using?
Comment 16 Marcel de Rooy 2019-11-21 13:26:42 UTC
(In reply to Jonathan Druart from comment #15)
> Which versions of Firefox are you using?

70.0.1
Comment 17 Jonathan Druart 2019-11-21 13:46:54 UTC
(In reply to Marcel de Rooy from comment #16)
> (In reply to Jonathan Druart from comment #15)
> > Which versions of Firefox are you using?
> 
> 70.0.1

I have exactly this version...
Comment 18 Jonathan Druart 2019-11-21 15:31:03 UTC
Created attachment 95664 [details] [review]
Bug 24061: Close the window after the page has been printed
Comment 19 Jonathan Druart 2019-11-21 15:33:56 UTC
(In reply to Jonathan Druart from comment #17)
> (In reply to Marcel de Rooy from comment #16)
> > (In reply to Jonathan Druart from comment #15)
> > > Which versions of Firefox are you using?
> > 
> > 70.0.1
> 
> I have exactly this version...

So, interestingly, or not, it did work on Firefox 70.0.1 but not on chromium.

This patch makes the use of the onafterprint event which sounds definitely the correct way. This one works with chromium and Firefox.
Comment 20 Jonathan Druart 2019-11-21 15:38:29 UTC
Not with Chrome...
Comment 21 Jonathan Druart 2019-11-21 15:47:06 UTC
(In reply to Jonathan Druart from comment #20)
> Not with Chrome...

https://www.w3schools.com/tags/ev_onafterprint.asp
It says from Chrome 63, so I think it's the way to go.
Comment 22 Marcel de Rooy 2019-11-22 08:06:10 UTC
Does not work fine with Chrome 62 too.
Also a problem with Edge.
Firefox seems to work.

Easier to increase the timeout?
Comment 23 Jonathan Druart 2019-11-22 09:07:32 UTC
Waiting for 1 second before closing the window? Looks very ugly to me.
Comment 24 Jonathan Druart 2019-11-22 09:17:20 UTC
Created attachment 95715 [details] [review]
Bug 24061: close after timeout if onafterprint no supported

Not supported on Chrome < 63
https://www.w3schools.com/tags/ev_onafterprint.asp
Comment 25 Jonathan Druart 2019-11-22 09:17:56 UTC
Let's do both then...
Comment 26 Marcel de Rooy 2019-11-22 12:23:02 UTC
(In reply to Jonathan Druart from comment #25)
> Let's do both then...

Seems to work in a quick test.
Firefox, Chrome and Edge.
Edge ask for permission to close the tab.

Maybe change 1000 to 500 or even less? 100 works with me on Chrome
Comment 27 Gabriel DeCarufel 2020-01-07 18:38:51 UTC
printing a public list from the OPAC in chrome now works with this patch.
Comment 28 Guillaume Paquet 2020-01-07 18:47:40 UTC
The patch was tested on Chrome 79 and worked properly.
Comment 29 Gabriel DeCarufel 2020-01-07 21:59:30 UTC
Created attachment 96971 [details] [review]
Bug 24061: close after timeout if onafterprint no supported

Not supported on Chrome < 63
https://www.w3schools.com/tags/ev_onafterprint.asp

Signed-off-by: Gabriel DeCarufel <gabriel@inlibro.com>
Comment 30 Katrin Fischer 2020-01-20 06:52:25 UTC
Created attachment 97597 [details] [review]
Bug 24061: Close the window after the page has been printed

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 31 Katrin Fischer 2020-01-20 06:52:29 UTC
Created attachment 97598 [details] [review]
Bug 24061: Close after timeout if onafterprint no supported

Not supported on Chrome < 63
https://www.w3schools.com/tags/ev_onafterprint.asp

Signed-off-by: Gabriel DeCarufel <gabriel@inlibro.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 32 Katrin Fischer 2020-01-20 06:53:44 UTC
Reported in November... moving forward as this works ok for me in all tested browsers (Chrome, Chromium, Firefox).
Comment 33 Martin Renvoize (ashimema) 2020-01-20 14:04:33 UTC
Nice work everyone!

Pushed to master for 20.05
Comment 34 Joy Nelson 2020-02-01 00:00:47 UTC
Pushed to 19.11.x branch for 19.11.03
Comment 35 Lucas Gass (lukeg) 2020-02-13 16:58:04 UTC
backported to 19.05.x for 19.05.08
Comment 36 Hayley Pelham 2020-02-14 03:27:03 UTC
Backported to 18.11.x for 18.11.14.