title: Puppeteer chrome get active/visible tab
body: <p>In a chrome extension you can use below to find the active tab in a window</p>
  
  <pre><code>chrome.tabs.query({
              currentWindow: true,
              active: true,
          }
  </code></pre>
  
  <p>I have a below code which connects to existing browser and get all the pages. I am not able to make out if there is a way for me to know which tab/page is currently the active one and get its url (<code>page.url()</code>, but which one from the the array to use?)</p>
  
  <pre><code>const puppeteer = require('puppeteer');
  
  debuggerUrl = "http://127.0.0.1:9999/json/version"
  
  const request = require('request');
  
  request(debuggerUrl, function (error, response, body) {
    data = JSON.parse(body);
    webSocketDebuggerUrl = data["webSocketDebuggerUrl"];
    console.log("Connecting to ", webSocketDebuggerUrl);
    puppeteer.connect({browserWSEndpoint: webSocketDebuggerUrl}).then(async browser =&gt; {
      var pages = await browser.pages();
      console.log(pages);
      console.log(await browser.targets())
      await browser.disconnect();
    })
  });
  </code></pre>