diff --git a/extension/chrome/elements/pgp_block.ts b/extension/chrome/elements/pgp_block.ts index e47474f762e..a2d138ae5f9 100644 --- a/extension/chrome/elements/pgp_block.ts +++ b/extension/chrome/elements/pgp_block.ts @@ -58,6 +58,8 @@ export class PgpBlockView extends View { }; public setHandlers = () => { + // Disable print button initially until printMailInfoHtml is ready + $('.pgp_print_button').prop('disabled', true).attr('data-test-print-ready', 'false'); $('.pgp_print_button').on( 'click', this.setHandler(() => this.printModule.printPGPBlock()) @@ -148,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; + // Enable print button now that data is ready + $('.pgp_print_button').prop('disabled', false).attr('data-test-print-ready', 'true'); } 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 bd1f60194aa..e79a09b931c 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 @@ -11,15 +11,9 @@ export class PgpBlockViewPrintModule { public printMailInfoHtml: string | undefined; public printPGPBlock = async () => { - // If printMailInfoHtml is not yet prepared, wait briefly to handle race conditions + // printMailInfoHtml should always be set when this function is called + // because the print button is disabled until the data arrives if (!this.printMailInfoHtml) { - 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.'); Catch.reportErr('printMailInfoHtml not prepared!'); return; diff --git a/test/source/tests/decrypt.ts b/test/source/tests/decrypt.ts index b5e0b92ae4c..5e5ca20d134 100644 --- a/test/source/tests/decrypt.ts +++ b/test/source/tests/decrypt.ts @@ -1183,8 +1183,7 @@ XZ8r4OC6sguP/yozWlkG+7dDxsgKQVBENeG6Lw== }) ); - // https://github.com/FlowCrypt/flowcrypt-browser/issues/6145 - test.skip( + test( 'decrypt - print feature in pgp block', testWithBrowser(async (t, browser) => { const msgId = '18ecbf57e1dfb9b5'; @@ -1192,6 +1191,8 @@ XZ8r4OC6sguP/yozWlkG+7dDxsgKQVBENeG6Lw== await page.waitForIframes(); const pgpBlock = await page.getFrame(['pgp_block.htm']); await pgpBlock.waitForSelTestState('ready'); + // Wait for print button to be enabled (data-test-print-ready="true") + await pgpBlock.waitAll('[data-test="action-print"][data-test-print-ready="true"]', { timeout: 30 }); const expectedPrintDateString = new Date(1712818847000).toLocaleString(); const printPage = await browser.newPageTriggeredBy(t, () => pgpBlock.click('@action-print')); await printPage.waitForContent('@print-date', expectedPrintDateString);