Open frankcollins3 opened 1 year ago
first approach I'm going with:
resolve: async () => {
const browser = await puppeteer.launch({headless: false})
const page = await browser.newPage(); // move these to be a few lines of code loewr within gotoJS() scope
const gotoJS = async (url) => {
if (typeof url === 'string') {
page.goto(url)
await page.screenshot({ path: url.slice(url.length - 20, url.length )})
} else {
return {err: 'error'}
}
}
set puppeteer.launch() && browser.newPage() to be within the scope of gotoJS()
part of this issue is that I thought the callback function that parsed for URL would suffice.
Specifically, page.goto() being invoked again, does not reassign the already declared browser window to a new url It opens up the browser again.
[9:33pm]
puppeteer: {
type: new GraphQLList(GraphQLString),
description: 'Invoke Puppeteer',
resolve: async () => {
const gotoJS = async (url) => {
let url_path = url;
let browserPromise = new Promise( (resolve, reject) => {
const browser = puppeteer.launch( {headless: false} )
.then( () => {
resolve(
page = browser.newPage(),
page.goto(url || url_path),
browser.close()
)
})
.reject( (err) => {
console.log('oh wow we have an error')
return err
})
browserPromise()
})
here is my promise that isn't working.
[9:42pm]
this code is causing the problems
the problem is that: a new browser tab and window appears, the page navigates to the URL, and without awaiting the second setTimeout()=> ... the code within that 2nd setTimeout() => is executed without await
first proposed approach: 1) use a Promise.all() 2) make use of the puppeteer method .close() -------> as in browser.close()