Tuesday 25 February 2020

Puppeteer with an array? And stupid google login issue.

Hi everyone, I need some assistance. 2 questions that I will preface with I'm a SysAdmin not a coder, please be gentle :)​1) With the code below working to take screenshots using puppeteer, how can I loop thru the function as an array? I'm thinking it has to be synchronous due to the screenshots? I want the array list to pass the URL and filename.2) I need to take screenshots of some google analytic reports. Stupid chrome (and chromium) is giving me " Couldn't sign you in....This browser or app may not be secure. " Of course if I just run chrome I can login just fine, but not using this code. I've even tried changing the user agent. Has anyone worked around this issue?​const puppeteer = require('puppeteer')// I need to use the userDataDir to store session and cookies.const takeScreenshot = async (x,y) => {const browser = await puppeteer.launch({headless: false, args: ['--start-maximized', '--password-store=basic'], executablePath: 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',userDataDir: './userdata/Default3/'});​const page = await browser.newPage();const options = {path: 'images/image' + y + '.png'};​await page.setViewport({ width: 1920, height: 1080 });await page.goto(x);await new Promise(resolve => setTimeout(resolve, 5000));await page.screenshot(options);await browser.close();}​takeScreenshot('http://datastudio.google.com', 'google1');​// How do I do something like this?// let sitearray = [['https://www.cnn.com','testb1'], ['https://www.google.com','testb2'];// sudo code: for A in sitearray do takeScreenshot (sitearray[A.0],sitearray[A.1]) ??????????????

Submitted February 25, 2020 at 04:10PM by ImCaffeinated_Chris

No comments:

Post a Comment