How to capture full page screenshot in Selenium 4 using Bidi API's?

I want to capture a full page screenshot in selenium 4 using Bidi API's/Chrome developer tools. https://www.selenium.dev/documentation/webdriver/bidirectional/bidi_api/

A sample for generating console logs through Bidi apis. Want to capture the full page screenshot and store it in a local directory.

const { Builder } = require('selenium-webdriver');
(async () => {
  try {
    let driver = new Builder()
      .forBrowser('chrome')
      .build();

    const cdpConnection = await driver.createCDPConnection('page');
    await driver.onLogEvent(cdpConnection, function (event) {
      console.log(event['args'][0]['value']);
    });
    await driver.executeScript('console.log("CDP connection established")');
    await driver.quit();
  } catch (e) {
    console.log(e);
  }
})()
How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum