async function getPageFromConnection(connection) {
  await connection.connect();
  const {targetInfo: mainTargetInfo} =
    await connection.sendCommand('Target.getTargetInfo', undefined);
  const {frameTree} = await connection.sendCommand('Page.getFrameTree', undefined);

  const channel = connection.channel_ || connection.rootSessionConnection_;
  const transport = channel.root_.transport_;

  const pptrConnection = new PptrConnection(mainTargetInfo.url, transport);

  const browser = await CdpBrowser._create(
    pptrConnection,
    [] /* contextIds */,
    false /* ignoreHTTPSErrors */
  );

  // We should be able to find the relevant page instantly, but just in case
  // the relevant tab target comes a bit delayed, check every time a new
  // target is seen.
  const targetPromise = browser.waitForTarget(async (target) => {
    const page = await target.page();
    if (page && page.mainFrame()._id === frameTree.frame.id) return true;
    return false;
  });
  const page = await Promise.race([
    targetPromise.then(target => target.page()),
    new Promise((_, reject) => {
      setTimeout(() => reject(new Error('Could not find relevant puppeteer page')), 5000);
    }),
  ]);
  return page;
}
@param {any} connection
@return {Promise<LH.Puppeteer.Page>}