Nuxt 2 reached end of life on 30 June 2024
It no longer receives bug fixes or security patches. Upgrade to Nuxt 4 or get extended support from HeroDevs
nuxt.renderAndGetWindow(url, options)
Get the window from a given URL of a Nuxt Application.
- Type:
Function Argument:
StringString: URL to render- Optional,
Object: options
- virtualConsole:
Boolean(default:true)
Returns:
Promise- Returns:
window
- Returns:
This method is made for test purposes.
To use this function, you have to install jsdom:
npm install --save-dev jsdomExample:
const { loadNuxt } = require('nuxt')
async function init() {
// Assuming you've already built your project
const nuxt = await loadNuxt({ for: 'start' })
await nuxt.listen(3000)
const window = await nuxt.renderAndGetWindow('http://localhost:3000')
// Display the head `<title>`
console.log(window.document.title)
nuxt.close()
}
init()