Kaizen Today I Learned by Ville Säävuori

Fetching JSON With Playwright

I wrote my first project using Playwright, an interesting headless browser API similar to Puppeteer but for all major browsers (Chromium, Firefox and Webkit). My first hurdle was reading a simple JSON response as opposed to a normal HTML page. The docs suggest attaching a listener to all requests and filtering what you want there, but I found the following to be easiest way:

page
  .goto(url)
  .then(async (response) => {
    const body = await response.body()
    content = await JSON.parse(body.toString())
  })

This breaks the async/await convention, but it works.

Tagged with , , , , ,

Published . Last modified .