0

for example I have a variable called link , I want to get the value of that variable after exucuting a page.goto() in puppeteer .

this is example code

//this is my link variable 
const link = "something";
 (async() => {
            const browser = await puppeteer.launch({
                headless: false,
                //args: ['--proxy-server=161.129.155.43:3128']
                timeout: 20000
            });
            browser.userAgent(browsers[0]);
            const page = await browser.newPage();

//called variable before goto() 
      console.log(link) //=>something

            await page.goto(url);

//called variable after goto() 
      console.log(link) //=>undefined

            await page.evaluate(() => {
            setTimeout(() => {
            document.getElementsByClassName("sA5rQ")[0].click();
                       }, 3000);
    })
            setTimeout(async() => {
                await browser.close();
            }, 60000);
        })();

as you see in comments inside my code the value after executing page.goto() are undefined and I can only use variables from that page in browser by reading and scraping data .

how can I pass the link variable inside the pupputeer browser page?

azdeviz
  • 597
  • 2
  • 9
  • 20
  • I can't see why your example would work like that. Consider posting your exact code instead. – Maxim Mazurok Jun 09 '20 at 00:39
  • this is the full code inside an api function for posting data , `app.post('/',(req,res)=>{//code}` – azdeviz Jun 09 '20 at 00:42
  • I have tried many times , I think when it runs the url all variables should be something inside the browser page and I can just controle what I have inside new browser page – azdeviz Jun 09 '20 at 00:45
  • In the code above, you're logging `link` inside your NodeJS program, not inside of the browser/puppeteer. – Maxim Mazurok Jun 09 '20 at 00:51
  • for example I want to set `document.getelementById('input').value=link` ,how can I let it be passed to the document element's value in browser? – azdeviz Jun 09 '20 at 00:58
  • That's another question: https://stackoverflow.com/questions/46088351/puppeteer-pass-variable-in-evaluate – Maxim Mazurok Jun 09 '20 at 01:20
  • yes , it is , it s what I m looking for exactly , thank you. – azdeviz Jun 09 '20 at 10:18

0 Answers0