How to Automate Microsoft Live Login with Playwright
On this page
Playwright allows us to automate logging in to a Microsoft Live account.
Steps
- We start at
https://login.live.com
- We provide the username and password, injected by using environment variables
- We are redirected to the main account page
const { chromium } = require('playwright')
;(async () => {
const browser = await chromium.launch({ headless: false })
const page = await browser.newPage()
await page.setViewport({ width: 1280, height: 800 })
await page.goto('https://login.live.com/')
await page.fill('[name="loginfmt"]', process.env.MSLIVE_USER)
await page.click('[type="submit"]')
await page.fill('input[type="password"]', process.env.MSLIVE_PWD)
await page.keyboard.press('Enter')
await browser.close()
})()
Run this example as follows. Replace the username and password placeholder with your own credentials.
MSLIVE_USER=username MSLIVE_PWD=password node mslive-login.js
SET MSLIVE_USER=username
SET MSLIVE_PWD=password
node mslive-login.js
This example does not work when you have 2-factor authentication enabled, and you might trigger a recaptcha check.
Takeaways
- Use environment variables to inject secrets.
- Wait for the navigation as your are redirected to Microsoft.
- Wait for the navigation as you are redirected back to the start site.