0

I am trying to do some scraping using a library and my code uses Node's async/await pattern.

I have defined a variable 'page' in function named 'sayhi' and I pass the same variable to function ex, I get error while running the code.

const puppeteer = require('puppeteer');

async function sayhi() {
  const browser = await puppeteer.launch({headless: false});
  const page = await browser.newPage();
  await page.goto('https://www.example.com/'); // 
  ex(page); //FAILS

  var frames2 = await newpage.frames(); // WORKS
}

function ex(newpage){
  var frames = await newpage.frames(); // FAILING
}

sayhi();
1
  • 1
    ex() needs to be made async Commented Mar 21, 2018 at 6:28

1 Answer 1

1

You're using await in a function that isn't an async function. Try this instead:

async function ex(newpage) {

If you need frames2 to run only after ex is finished completely, you'll also want to await ex(page); in sayhi.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a ton. I did as suggested. Solved my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.