diff --git a/lib/core/renderer.js b/lib/core/renderer.js index 996ef6ff6e..f35275f833 100644 --- a/lib/core/renderer.js +++ b/lib/core/renderer.js @@ -421,12 +421,18 @@ module.exports = class Renderer { window.scrollTo = () => {} } } + const jsdomErrHandler = err => { throw err } if (opts.virtualConsole !== false) { - options.virtualConsole = new jsdom.VirtualConsole().sendTo(console, { omitJSDOMErrors: true }) - options.virtualConsole.on('jsdomError', err => { throw err }) + options.virtualConsole = new jsdom.VirtualConsole().sendTo(console, { omitJSDOMErrors: false }) + // throw error when window creation failed + options.virtualConsole.on('jsdomError', jsdomErrHandler) } url = url || 'http://localhost:3000' const { window } = await jsdom.JSDOM.fromURL(url, options) + if (opts.virtualConsole !== false) { + // after window initialized successfully + options.virtualConsole.removeListener('jsdomError', jsdomErrHandler) + } // If Nuxt could not be loaded (error from the server-side) const nuxtExists = window.document.body.innerHTML.includes( this.options.render.ssr ? 'window.__NUXT__' : '
'