|
| 1 | +/** |
| 2 | + * @name Microsoft Live Login |
| 3 | + * |
| 4 | + * @desc Logs into MS Live. |
| 5 | + * Provide your username and password as environment variables when running the script, i.e: |
| 6 | + * linux: |
| 7 | + * MSLIVE_USER=myuser MSLIVE_PWD=mypassword node mslive.js |
| 8 | + * Windows users: |
| 9 | + * SET MSLIVE_USER=myuser |
| 10 | + * SET MSLIVE_PWD=mypassword |
| 11 | + * node mslive.js |
| 12 | + * for more info see here: https://stackoverflow.com/questions/9249830/how-can-i-set-node-env-production-on-windows |
| 13 | + */ |
| 14 | +const puppeteer = require('puppeteer'); |
| 15 | + |
| 16 | + |
| 17 | +(async() => { |
| 18 | + |
| 19 | + const browser = await puppeteer.launch({ headless: false }) |
| 20 | + const page = await browser.newPage() |
| 21 | + |
| 22 | + await page.setViewport({ width: 1280, height: 800 }) |
| 23 | + await page.goto('https://login.live.com/',{waitUntil: ['networkidle2'] }) |
| 24 | + |
| 25 | + const navigationPromise = page.waitForNavigation({waitUntil: ['networkidle2'] }) |
| 26 | + |
| 27 | + await page.waitForSelector('[name="loginfmt"]') |
| 28 | + await page.type('[name="loginfmt"]', process.env.MSLIVE_USER) |
| 29 | + await page.click('[type="submit"]') |
| 30 | + |
| 31 | + await navigationPromise |
| 32 | + //we need to use waitForResponse because we are dealing with AJAX - no page navigation |
| 33 | + await page.waitForResponse(response => response.status() === 200); |
| 34 | + await page.waitForSelector('input[type="password"]', { visible: true }) |
| 35 | + await page.type('input[type="password"]',process.env.MSLIVE_PWD) |
| 36 | + await page.keyboard.press("Enter") |
| 37 | + |
| 38 | + await navigationPromise |
| 39 | + |
| 40 | + await browser.close() |
| 41 | + |
| 42 | +})(); |
| 43 | + |
| 44 | + |
| 45 | + |
0 commit comments