Puppeteer: Managing Multiple Browser Tabs?

I have a Puppeteer workflow that opens a new tab to retrieve an App ID from a developer registration page. How can I identify and manage that tab?

const puppeteer = require('puppeteer');

(async () => {
  const browserInstance = await puppeteer.launch({ headless: false });
  const mainPage = await browserInstance.newPage();
  await mainPage.goto('https://example-register.com', { waitUntil: 'networkidle' });
  await mainPage.click('.launch-appid');
  const pagesList = await browserInstance.pages();
  const newTab = pagesList[pagesList.length - 1];
  const retrievedId = await newTab.$eval('#appid-text', el => el.textContent);
  await newTab.close();
  await mainPage.type('#appid-input', retrievedId);
  await mainPage.click('#submit-form');
  await browserInstance.close();
})();

hey, try using page.on(‘targetcreated’) to listen for new tabs. i had issues with the pages array order before, so this event catches new tabs right away. u might also check on browser.target() to make sure u get the right one.