From 81dcf7b6be66920260a60908aa4b86e7530f6e17 Mon Sep 17 00:00:00 2001 From: Radics Laszlo Date: Tue, 18 Jun 2019 06:23:45 +0200 Subject: [PATCH] fix: zero size iframe rendering (#1863) --- .../iframe-element-container.ts | 4 ++-- src/render/canvas/canvas-renderer.ts | 24 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/dom/replaced-elements/iframe-element-container.ts b/src/dom/replaced-elements/iframe-element-container.ts index 06fcccc..001ed95 100644 --- a/src/dom/replaced-elements/iframe-element-container.ts +++ b/src/dom/replaced-elements/iframe-element-container.ts @@ -15,8 +15,8 @@ export class IFrameElementContainer extends ElementContainer { constructor(iframe: HTMLIFrameElement) { super(iframe); this.src = iframe.src; - this.width = parseInt(iframe.width, 10); - this.height = parseInt(iframe.height, 10); + this.width = parseInt(iframe.width, 10) || 0; + this.height = parseInt(iframe.height, 10) || 0; this.backgroundColor = this.styles.backgroundColor; try { if ( diff --git a/src/render/canvas/canvas-renderer.ts b/src/render/canvas/canvas-renderer.ts index 0026654..d15ed1e 100644 --- a/src/render/canvas/canvas-renderer.ts +++ b/src/render/canvas/canvas-renderer.ts @@ -306,17 +306,19 @@ export class CanvasRenderer { }); const canvas = await iframeRenderer.render(container.tree); - this.ctx.drawImage( - canvas, - 0, - 0, - container.width, - container.width, - container.bounds.left, - container.bounds.top, - container.bounds.width, - container.bounds.height - ); + if (container.width && container.height) { + this.ctx.drawImage( + canvas, + 0, + 0, + container.width, + container.height, + container.bounds.left, + container.bounds.top, + container.bounds.width, + container.bounds.height + ); + } } if (container instanceof InputElementContainer) {