From 3b75d3271e77b6eee4be6ef028e58e01cf8d52f9 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 30 Oct 2025 14:54:28 -0700 Subject: [PATCH] Fix: delay iframe DOM removal for print in FF --- .../document-detail.component.spec.ts | 4 ++++ .../document-detail/document-detail.component.ts | 16 +++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src-ui/src/app/components/document-detail/document-detail.component.spec.ts b/src-ui/src/app/components/document-detail/document-detail.component.spec.ts index 752df3b21c..db537e1b28 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.spec.ts +++ b/src-ui/src/app/components/document-detail/document-detail.component.spec.ts @@ -1489,6 +1489,8 @@ describe('DocumentDetailComponent', () => { mockContentWindow.onafterprint(new Event('afterprint')) } + tick(500) + expect(removeChildSpy).toHaveBeenCalledWith(mockIframe) expect(revokeObjectURLSpy).toHaveBeenCalledWith('blob:mock-url') @@ -1563,6 +1565,8 @@ describe('DocumentDetailComponent', () => { mockIframe.onload(new Event('load')) } + tick(500) + expect(toastSpy).toHaveBeenCalled() expect(removeChildSpy).toHaveBeenCalledWith(mockIframe) expect(revokeObjectURLSpy).toHaveBeenCalledWith('blob:mock-url') diff --git a/src-ui/src/app/components/document-detail/document-detail.component.ts b/src-ui/src/app/components/document-detail/document-detail.component.ts index 48ddf61e5b..4e0d3259f8 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.ts +++ b/src-ui/src/app/components/document-detail/document-detail.component.ts @@ -21,7 +21,7 @@ import { dirtyCheck, DirtyComponent } from '@ngneat/dirty-check-forms' import { PDFDocumentProxy, PdfViewerModule } from 'ng2-pdf-viewer' import { NgxBootstrapIconsModule } from 'ngx-bootstrap-icons' import { DeviceDetectorService } from 'ngx-device-detector' -import { BehaviorSubject, Observable, of, Subject } from 'rxjs' +import { BehaviorSubject, Observable, of, Subject, timer } from 'rxjs' import { catchError, debounceTime, @@ -1448,13 +1448,19 @@ export class DocumentDetailComponent iframe.contentWindow.focus() iframe.contentWindow.print() iframe.contentWindow.onafterprint = () => { - document.body.removeChild(iframe) - URL.revokeObjectURL(blobUrl) + timer(500).subscribe(() => { + // delay to avoid print failure + document.body.removeChild(iframe) + URL.revokeObjectURL(blobUrl) + }) } } catch (err) { this.toastService.showError($localize`Print failed.`, err) - document.body.removeChild(iframe) - URL.revokeObjectURL(blobUrl) + timer(500).subscribe(() => { + // delay to avoid print failure + document.body.removeChild(iframe) + URL.revokeObjectURL(blobUrl) + }) } } }, -- 2.47.3