zbeucler

Puppeter help

Jul 21st, 2020
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //npm install clipboardy
  2. //npm i puppeteer
  3.  
  4. // https://nitayneeman.com/posts/getting-to-know-puppeteer-using-practical-examples/
  5.  
  6. // gmail keyboard shortcuts
  7. // https://support.google.com/mail/answer/6594?co=GENIE.Platform%3DDesktop&hl=en
  8.  
  9. const puppeteer = require('puppeteer');
  10.  
  11. const clipboard = require('clipboardy');
  12.  
  13. var userClipboard = clipboard.readSync();
  14. //console.log(clipboard.readSync()); // get clipboard contents
  15.  
  16. (async () => {
  17.   const browser = await puppeteer.launch({ headless: false });
  18.   const page = await browser.newPage();
  19.   await page.goto('https://accounts.google.com/signin/v2/identifier?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin');
  20.  
  21.   // enter email username
  22.   console.log("Entering email...");
  23.   await page.keyboard.sendCharacter('#############@gmail.com');
  24.   await page.keyboard.press(String.fromCharCode(13));
  25.  
  26.   //await new Promise(resolve => setTimeout(resolve, 1500));
  27.      
  28.   await page.waitForNavigation({ waitUntil: 'networkidle2' });
  29.  
  30.   // enter email password
  31.   console.log("Entering password...");
  32.   await page.keyboard.sendCharacter('##########', {delay: 100});
  33.   await page.keyboard.press(String.fromCharCode(13));
  34.  
  35.   await new Promise(resolve => setTimeout(resolve, 5000)); // wait for gmail to load a little bit (wait for navigation doesnt really work for some reason)
  36.    
  37.   const emailPage = await browser.newPage();
  38.   await emailPage.goto('https://mail.google.com/mail/u/0/#inbox/##################', {waitUntil: 'domcontentloaded'});
  39.   console.log("Thread opened...");
  40.    
  41.   await emailPage.waitForNavigation({ waitUntil: 'networkidle2' });
  42.  
  43.   await emailPage.keyboard.press(String.fromCharCode(82));
  44.  
  45.   await emailPage.keyboard.type('text', {delay: 100});
  46.  
  47.   await emailPage.keyboard.press(String.fromCharCode(13)); // new line
  48.  
  49.   await emailPage.keyboard.type(userClipboard, {delay: 100});
  50.  
  51.   await emailPage.keyboard.down('Command');
  52.   await emailPage.keyboard.press(String.fromCharCode(13));
  53.   await emailPage.keyboard.up('Command');
  54.  
  55.   //await emailPage.screenshot({path: 'screenshot.png'});
  56.    
  57.   await new Promise(resolve => setTimeout(resolve, 5000));
  58.    
  59.   await browser.close();
  60.   console.log("done");
  61. })();
Add Comment
Please, Sign In to add comment