1
1
import { type Font , type PublicUseVueToPrintProps } from "./types" ;
2
2
import * as ShadowDomSupport from "./supports/shadow-dom" ;
3
3
import { deepCloneNode } from "./clone-node" ;
4
- import { isRef , toValue } from "vue" ;
4
+ import { toValue } from "vue" ;
5
5
6
6
/**
7
7
* The default props in Vue are set within vueToPrintProps too.
@@ -202,8 +202,17 @@ export function useVueToPrint(props: PublicUseVueToPrintProps) {
202
202
return ;
203
203
}
204
204
205
- // React components can return a bare string as a valid JSX response
206
- const clonedContentNodes = await deepCloneNode ( contentNodes ) ;
205
+ /**
206
+ * Allow printing to continue even if some resources fail to load (e.g. bad image URLs, invalid fonts, etc.)
207
+ */
208
+ const { node : clonedContentNodes , result } = await deepCloneNode ( contentNodes ) ;
209
+ for ( const promise of result ) {
210
+ if ( promise . status === 'fulfilled' ) continue ;
211
+ logMessages ( [
212
+ `An error occurred while cloning the content to print. Printing will continue, but some content may be missing.` ,
213
+ `Error: ${ promise . reason } ` ,
214
+ ] , "warning" )
215
+ }
207
216
// const isText = clonedContentNodes instanceof Text;
208
217
209
218
const globalStyleLinkNodes = document . querySelectorAll ( "link[rel~='stylesheet']" ) ;
@@ -416,7 +425,8 @@ export function useVueToPrint(props: PublicUseVueToPrintProps) {
416
425
} ;
417
426
418
427
const handleRemoveIframe = ( force ?: boolean ) => {
419
- const { removeAfterPrint } = props ;
428
+ const removeAfterPrint = toValue ( props . removeAfterPrint ) ;
429
+
420
430
421
431
if ( force || removeAfterPrint ) {
422
432
// The user may have removed the iframe in `onAfterPrint`
@@ -428,7 +438,7 @@ export function useVueToPrint(props: PublicUseVueToPrintProps) {
428
438
} ;
429
439
430
440
const logMessages = ( messages : unknown [ ] , level : "error" | "warning" | "debug" = "error" ) => {
431
- const { suppressErrors } = props ;
441
+ const suppressErrors = toValue ( props . suppressErrors ) ;
432
442
433
443
if ( ! suppressErrors ) {
434
444
if ( level === "error" ) {
0 commit comments