I am trying to get mock data for puppeteer for a dynamic vue application.
Here is what I have (with placeholder API urls):
await page.setRequestInterception(true)
page.on('request', (request) => {
console.log(request.url())
if (request.url() === 'URL HERE') {
request.respond({
status: 200,
content: 'application/json',
body: JSON.stringify(MockData.image)
})
} else if (request.url() === 'URL HERE') {
request.respond({
status: 200,
content: 'application/json',
body: JSON.stringify(MockData.text)
})
} else {
request.continue()
}
})
This snippet sits above all logic where the requests would come through, and the URLS are correct.
The mocked calls do not seem to finish or come through correctly. Is this a problem with my setup?
Solution was to call launch with chromium security disabled.
browser = await puppeteer.launch({
args: ['--disable-web-security']
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With