Skip to content

Instantly share code, notes, and snippets.

@nmcclain
Last active Jun 22, 2021
Embed
What would you like to do?
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