Skip to content

Instantly share code, notes, and snippets.

@nmcclain
Last active June 22, 2021 22:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmcclain/30e4f5ee231e606bc4a1dcedef1c551f to your computer and use it in GitHub Desktop.
Save nmcclain/30e4f5ee231e606bc4a1dcedef1c551f to your computer and use it in GitHub Desktop.
Get Notion.so token_v2 with username/password
// DANGER: Run this too frequently and you can lock out your Notion account.
// Once a day should be sufficient for most use cases.
//
// npm i -D playwright
// export NOTION_TOKEN=`node gettoken/gettoken.js`
const { chromium } = require('playwright');
const user = 'XXXX';
const pass = 'YYYY';
(async () => {
const browser = await chromium.launch({ headless: true, slowMo: 50 });
const ctx = await browser.newContext();
const page = await ctx.newPage();
await page.goto('https://www.notion.so/login');
await page.fill('#notion-email-input-1', user);
await page.click('text=Continue with email');
await page.fill('#notion-password-input-2', pass);
await page.click('text=Continue with password');
await page.waitForSelector('div.notion-sidebar'); //, { state: 'attached' });
const cookies = await ctx.cookies(['https://www.notion.so/']);
for (const cook of cookies) {
if (cook.name == 'token_v2') {
console.log(cook.value);
}
}
await ctx.close();
await browser.close();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment