threema-ch / threema-web

The Threema Web application.
GNU Affero General Public License v3.0
998 stars 107 forks source link

Firefox: PDFs are opened in same tab #1118

Closed threema-danilo closed 2 years ago

threema-danilo commented 2 years ago

Bug Description

In current versions of Firefox, when clicking on a PDF file, it is not downloaded, but instead opened in the same tab. This affects both current and old version of Threema Web, I suspect this was caused by a behavioral change in newer Firefox versions.

lgrahl commented 2 years ago

Happens on a lot of pages, so I'm not even sure we should do anything about it. Agree it's annoying though. Maybe there's a bugzilla bug?

lgrahl commented 2 years ago

Found this so far: https://bugzilla.mozilla.org/show_bug.cgi?id=1759835

threema-danilo commented 2 years ago

A potential workaround is downloading PDF files using the media type application/octet-stream, one of our support staff said that this seems to help. It's a ugly hack for a problem in Firefox, but if it works it might be a valid workaround. Opening PDFs is probably quite a common use case for Threema Web, so this should not break (it logs you out of the current session).

I'll take a closer look this afternoon. We're using a method that should always result in a download, so I suspect that Firefox is doing something wrong here. If I can confirm that, I'll comment on the Bugzilla ticket.

lgrahl commented 2 years ago

Found another longer discussion we might want to chime in: https://bugzilla.mozilla.org/show_bug.cgi?id=1756980#c5 (sigh, blaming bad UX while not even knowing the use case, like SPA with state in memory... come on)

We're using file-saver which uses target=_blank, so this would be the most fitting bug I guess: https://bugzilla.mozilla.org/show_bug.cgi?id=1759916

threema-danilo commented 2 years ago

Ugh, so they intentionally ignore the download attribute and Content-Disposition: attachment? https://bugzilla.mozilla.org/show_bug.cgi?id=1756980#c7

threema-danilo commented 2 years ago

We're using file-saver which uses target=_blank, so this would be the most fitting bug I guess: https://bugzilla.mozilla.org/show_bug.cgi?id=1759916

file-saver uses a lot of different approaches depending on the browser: https://github.com/eligrey/FileSaver.js/blob/master/src/FileSaver.js In our case (Firefox) an approach with a.href = URL.createObjectURL(blob) followed by click(a) is used.

Fun fact from bugzilla 1756980:

This also happens on WhatsApp web now. PDF files are opened in the same tab, although pressing the back button does re-logins the users. But I think this shows that this behavior is not expected.

For now, I'll add the ugly application/octet-stream workaround hack for Firefox, which does seem to work.

dbrgn commented 2 years ago

For the record, the change was finally reverted in Firefox 103: https://bugzilla.mozilla.org/show_bug.cgi?id=1756980#c71