diff --git a/lib/core/renderer.js b/lib/core/renderer.js index aea3be7d60..5826568243 100644 --- a/lib/core/renderer.js +++ b/lib/core/renderer.js @@ -421,8 +421,11 @@ module.exports = class Renderer { window.scrollTo = () => {} } } + const jsdomErrHandler = err => { throw err } if (opts.virtualConsole !== false) { options.virtualConsole = new jsdom.VirtualConsole().sendTo(console) + // throw error when window creation failed + options.virtualConsole.on('jsdomError', jsdomErrHandler) } url = url || 'http://localhost:3000' const { window } = await jsdom.JSDOM.fromURL(url, options) @@ -440,6 +443,10 @@ module.exports = class Renderer { await new Promise(resolve => { window._onNuxtLoaded = () => resolve(window) }) + if (opts.virtualConsole !== false) { + // after window initialized successfully + options.virtualConsole.removeListener('jsdomError', jsdomErrHandler) + } // Send back window object return window }