I am using Puppeteer to gather a list of companies that hire remotely. The page I am trying to collect the data from has a call to action that is not an <a href="" blank"_tab"
, but a <button></button>
. The button doesn't have any data attribute either, that gives a hint as to what the URL of the page that gets opened in a new tab, when I click the button, is. I am now trying to find a way to catch the opening of the new tab, by clicking the said button, to then fetch the URL of the newly opened tab. Is this possible with puppeteer?
Asked
Active
Viewed 176 times
1

Kenny
- 13
- 3
-
1when its opening a new tab why don't just copy the url from the new tab? – ValiSpaceProgramming Apr 16 '22 at 21:43
-
@ValiSpaceProgramming that's what I am trying to figure out how to do. So far, I've seen methods that enable me to open a new page, but those methods require me to provide an URL. But as I've highlighted it's impossible for me to know what the URL is, as the site I'm trying to get the information from, doesn't use an A tag but a button. And as far as I have seen, I don't see a method that enables me to capture the opening of new tab. – Kenny Apr 17 '22 at 23:02
1 Answers
0
The solution is to extract all pages of the browser via the browser.pages()
method call.
In your puppeteer project you always start by initialising the browser. The puppeteer virtual browser does contain the method pages(). Usage of pages().
What you have to do now: At first get the current url of the current page you are on. Then stream the result of the browser.pages() method. While streaming the array you can just get the index of your current tab. The tab you just opened using the button is the page with that index + 1 (the next element in the array)...

ValiSpaceProgramming
- 500
- 6
- 13