From d52ef92a97e50ff1eeb0d6624033445bf8964cd6 Mon Sep 17 00:00:00 2001 From: Ioan Moldovan Date: Wed, 1 Oct 2025 20:35:57 -0300 Subject: [PATCH 1/3] fix: print function not working --- extension/chrome/elements/pgp_block.ts | 16 ++++++++++++++++ .../pgp_block_modules/pgp-block-print-module.ts | 12 ++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/extension/chrome/elements/pgp_block.ts b/extension/chrome/elements/pgp_block.ts index 6aeac1f16b8..3eead83806b 100644 --- a/extension/chrome/elements/pgp_block.ts +++ b/extension/chrome/elements/pgp_block.ts @@ -13,6 +13,7 @@ import { PgpBlockViewPrintModule } from './pgp_block_modules/pgp-block-print-mod import { PgpBlockViewQuoteModule } from './pgp_block_modules/pgp-block-quote-module.js'; import { PgpBlockViewRenderModule } from './pgp_block_modules/pgp-block-render-module.js'; import { CommonHandlers, Ui } from '../../js/common/browser/ui.js'; +import { Catch } from '../../js/common/platform/catch.js'; import { View } from '../../js/common/view.js'; import { BrowserMsg } from '../../js/common/browser/browser-msg.js'; @@ -57,6 +58,8 @@ export class PgpBlockView extends View { }; public setHandlers = () => { + // Hide print button until printMailInfo is ready to avoid race conditions + $('.pgp_print_button').hide(); $('.pgp_print_button').on( 'click', this.setHandler(() => this.printModule.printPGPBlock()) @@ -67,6 +70,17 @@ export class PgpBlockView extends View { BrowserMsg.addListener('confirmation_result', CommonHandlers.createAsyncResultHandler()); BrowserMsg.listen(this.getDest()); BrowserMsg.send.pgpBlockReady(this, { frameId: this.frameId, messageSender: this.getDest() }); + // Proactively re-send readiness a few times in case the relay/association isn't ready yet, + // to ensure printMailInfo is delivered reliably + let resendAttempts = 0; + const resendInterval = Catch.setHandledInterval(() => { + if (this.printModule.printMailInfoHtml || resendAttempts >= 6) { + clearInterval(resendInterval); + return; + } + resendAttempts++; + BrowserMsg.send.pgpBlockReady(this, { frameId: this.frameId, messageSender: this.getDest() }); + }, 500); // Added this listener to handle cases where 'inbox_page/setup-webmail-content-script' is not ready to retrieve 'pgpBlockReady' events. // This can occur if 'setHandlers' is called before 'Inbox.setHandlers' is fully initialized. // https://github.com/FlowCrypt/flowcrypt-browser/pull/5783#discussion_r1663636264 @@ -136,6 +150,8 @@ export class PgpBlockView extends View { if (data?.printMailInfo) { Xss.sanitizeRender('.print_user_email', data.printMailInfo.userNameAndEmail); this.printModule.printMailInfoHtml = data.printMailInfo.html; + // Now that main print content is prepared, show the print button + $('.pgp_print_button').show(); } if (data?.renderAsRegularContent) { this.renderModule.renderAsRegularContent(data.renderAsRegularContent); diff --git a/extension/chrome/elements/pgp_block_modules/pgp-block-print-module.ts b/extension/chrome/elements/pgp_block_modules/pgp-block-print-module.ts index 8c9321b89e7..c04e3ebd7cb 100644 --- a/extension/chrome/elements/pgp_block_modules/pgp-block-print-module.ts +++ b/extension/chrome/elements/pgp_block_modules/pgp-block-print-module.ts @@ -3,15 +3,23 @@ 'use strict'; import { Time } from '../../../js/common/browser/time.js'; -import { Catch } from '../../../js/common/platform/catch.js'; +import { Ui } from '../../../js/common/browser/ui.js'; import { Xss } from '../../../js/common/platform/xss.js'; export class PgpBlockViewPrintModule { public printMailInfoHtml: string | undefined; public printPGPBlock = async () => { + // If printMailInfoHtml is not yet prepared, wait briefly to handle race conditions if (!this.printMailInfoHtml) { - Catch.reportErr('printMailInfoHtml not prepared!'); + for (let i = 0; i < 6 && !this.printMailInfoHtml; i++) { + await Time.sleep(200); + } + } + // If still not prepared, skip printing entirely + if (!this.printMailInfoHtml) { + // Last resort: inform the user + void Ui.modal.error('Unable to get metadata for this email. Please refresh the page and try again.'); return; } const w = window.open(); From ccacf7ab4a816422b779a31b0e117b32d04a49b8 Mon Sep 17 00:00:00 2001 From: Ioan Moldovan Date: Wed, 1 Oct 2025 22:33:52 -0300 Subject: [PATCH 2/3] fix: test --- extension/chrome/elements/pgp_block.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/extension/chrome/elements/pgp_block.ts b/extension/chrome/elements/pgp_block.ts index 3eead83806b..e47474f762e 100644 --- a/extension/chrome/elements/pgp_block.ts +++ b/extension/chrome/elements/pgp_block.ts @@ -58,8 +58,6 @@ export class PgpBlockView extends View { }; public setHandlers = () => { - // Hide print button until printMailInfo is ready to avoid race conditions - $('.pgp_print_button').hide(); $('.pgp_print_button').on( 'click', this.setHandler(() => this.printModule.printPGPBlock()) @@ -150,8 +148,6 @@ export class PgpBlockView extends View { if (data?.printMailInfo) { Xss.sanitizeRender('.print_user_email', data.printMailInfo.userNameAndEmail); this.printModule.printMailInfoHtml = data.printMailInfo.html; - // Now that main print content is prepared, show the print button - $('.pgp_print_button').show(); } if (data?.renderAsRegularContent) { this.renderModule.renderAsRegularContent(data.renderAsRegularContent); From 9e0d0c6d5cb916fd4fced1c287ddd480228b8512 Mon Sep 17 00:00:00 2001 From: Ioan Moldovan Date: Wed, 8 Oct 2025 22:07:13 -0300 Subject: [PATCH 3/3] fix: pr reviews --- .../chrome/elements/pgp_block_modules/pgp-block-print-module.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extension/chrome/elements/pgp_block_modules/pgp-block-print-module.ts b/extension/chrome/elements/pgp_block_modules/pgp-block-print-module.ts index c04e3ebd7cb..bd1f60194aa 100644 --- a/extension/chrome/elements/pgp_block_modules/pgp-block-print-module.ts +++ b/extension/chrome/elements/pgp_block_modules/pgp-block-print-module.ts @@ -3,6 +3,7 @@ 'use strict'; import { Time } from '../../../js/common/browser/time.js'; +import { Catch } from '../../../js/common/platform/catch.js'; import { Ui } from '../../../js/common/browser/ui.js'; import { Xss } from '../../../js/common/platform/xss.js'; @@ -20,6 +21,7 @@ export class PgpBlockViewPrintModule { if (!this.printMailInfoHtml) { // Last resort: inform the user void Ui.modal.error('Unable to get metadata for this email. Please refresh the page and try again.'); + Catch.reportErr('printMailInfoHtml not prepared!'); return; } const w = window.open();