Q:

nodejs puppeteer How can I type input inside an iframe?

I am trying to type my username on a website but the input box is inside an iframe, I have tried this code to locate the element inside the iframe but I keep getting an error  JSHandles can be evaluated only in the context they were created!
const puppeteer = require('puppeteer');
(async () => {
  const browser = await puppeteer.launch({headless: false});
  const page = await browser.newPage();
  await page.goto("www.examplesite.com", { waitUntil: 'networkidle0' })
  await sleep(1000)
  const myframe = await page.frames()[2];        
  const userselector = await myframe.$('input[name="usernameinput"]')
  await page.type(userselector, "myusername")
  await page.screenshot({path: 'example.png'});
  await browser.close();
})();

A:

The type function expects a selector string not a handle. So, as the frame also has a type function you could do:
await myframe.type('input[name="usernameinput"]', "myusername")

