Last active
September 28, 2017 14:31
-
-
Save drdrsh/f0f367127d8f139b7712dff73aad8bf4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getUserInput(missing_record) { | |
const puppeteer = require('puppeteer'); | |
return new Promise(async (resolve, reject) => { | |
//This message we will show the user | |
const prompt_msg = `Missing data: ${missing_record.desc}, please input value \n`; | |
//Construct a URL using longitude and latitude values from the record | |
const url = `https://www.google.com/maps/@?api=1&map_action=map¢er=${missing_record.lat},${missing_record.lng}&zoom=10`; | |
//Create a browser object, we want the user to interact so we set headless to be false | |
const browser = await puppeteer.launch({'headless': false}); | |
//Create a new page (think new tab) | |
const page = await browser.newPage(); | |
//Goto Google maps | |
await page.goto(url); | |
const result = await page.evaluate((msg) => { | |
/* | |
This function will run within our puppeteer browser window, and if we return a promise, | |
page.evaluate() will wait for it to resolve, so we return a promise that resolves | |
when the user responds | |
*/ | |
return new Promise((resolve, reject) => { | |
resolve(prompt(msg)); | |
}); | |
}, prompt_msg); | |
//Close our browser | |
await browser.close(); | |
//Return user input to the calling method | |
resolve(result); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment