diff --git a/src/lib/litegraph/src/DragAndScale.ts b/src/lib/litegraph/src/DragAndScale.ts index c71fca2d2..d2e35252d 100644 --- a/src/lib/litegraph/src/DragAndScale.ts +++ b/src/lib/litegraph/src/DragAndScale.ts @@ -192,8 +192,14 @@ export class DragAndScale { bounds: ReadOnlyRect, { zoom = 0.75 }: { zoom?: number } = {} ): void { - const cw = this.element.width / window.devicePixelRatio - const ch = this.element.height / window.devicePixelRatio + //If element hasn't initialized (browser tab is in background) + //it has a size of 300x150 and a more reasonable default is used instead. + const [width, height] = + this.element.width === 300 && this.element.height === 150 + ? [1920, 1080] + : [this.element.width, this.element.height] + const cw = width / window.devicePixelRatio + const ch = height / window.devicePixelRatio let targetScale = this.scale if (zoom > 0) {