Add a workaround for printing the backup codes in Safari
authorAlexander Ebert <ebert@woltlab.com>
Thu, 12 Oct 2023 12:14:25 +0000 (14:14 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 12 Oct 2023 12:14:25 +0000 (14:14 +0200)
See https://www.woltlab.com/community/thread/301990-woltlab-kundenbereich-ausdrucken-der-wiederherstellungscodes-funktioniert-nicht/

com.woltlab.wcf/templates/multifactorManageBackup.tpl

index 9312a2fd50317afa7c5fe3bfcd9262670215b0c3..cb7ebcc27ae0e399df6694f97491951be2e3f366 100644 (file)
                        {lang}wcf.user.security.multifactor.backup.print{/lang}
                        <script>
                        document.currentScript.closest('button').addEventListener('click', () => {
-                               window.print();
+                               try {
+                                       // Safari refuses to execute `window.print()` if there are
+                                       // any in-flight requests.
+                                       document.execCommand("print", false, null);
+                               } catch {
+                                       window.print();
+                               }
                        });
                        </script>
                </button>