54 lines
1.9 KiB
JavaScript
54 lines
1.9 KiB
JavaScript
|
|
import { createRequire } from 'module';
|
||
|
|
const require = createRequire(import.meta.url);
|
||
|
|
const UserAgent = require('user-agents');
|
||
|
|
import playwright from 'playwright-extra';
|
||
|
|
const { chromium } = playwright;
|
||
|
|
|
||
|
|
const optionsBrowser = {
|
||
|
|
headless: false,
|
||
|
|
args: [
|
||
|
|
'--disable-blink-features=AutomationControlled',
|
||
|
|
'--no-sandbox',
|
||
|
|
'--disable-web-security',
|
||
|
|
'--disable-infobars',
|
||
|
|
'--disable-extensions',
|
||
|
|
'--start-maximized',
|
||
|
|
'--window-size=1280,720',
|
||
|
|
],
|
||
|
|
};
|
||
|
|
const browser = await chromium.launch(optionsBrowser);
|
||
|
|
|
||
|
|
const optionsContext = {
|
||
|
|
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36',
|
||
|
|
locale: 'ko-KR',
|
||
|
|
viewport: { width: 1280, height: 720 },
|
||
|
|
deviceScaleFactor: 1,
|
||
|
|
extraHTTPHeaders: {
|
||
|
|
'sec-ch-ua': '"Not;A=Brand";v="99", "Google Chrome";v="139", "Chromium";v="139"',
|
||
|
|
'sec-ch-ua-arch': '"arm"',
|
||
|
|
'sec-ch-ua-bitness': '"64"',
|
||
|
|
'sec-ch-ua-form-factors': '"Desktop"',
|
||
|
|
'sec-ch-ua-full-version': '"139.0.7258.154"',
|
||
|
|
'sec-ch-ua-full-version-list': '"Not;A=Brand";v="99.0.0.0", "Google Chrome";v="139.0.7258.154", "Chromium";v="139.0.7258.154"',
|
||
|
|
'sec-ch-ua-mobile': '?0',
|
||
|
|
'sec-ch-ua-model': '""',
|
||
|
|
'sec-ch-ua-platform': '"macOS"',
|
||
|
|
'sec-ch-ua-platform-version': '"15.6.1"',
|
||
|
|
'sec-ch-ua-wow64': '?0',
|
||
|
|
},
|
||
|
|
};
|
||
|
|
|
||
|
|
const context = await browser.newContext(optionsContext);
|
||
|
|
const page = await context.newPage();
|
||
|
|
await page.goto('https://studio.youtube.com/');
|
||
|
|
|
||
|
|
// Give 90 seconds to complete the manual login.
|
||
|
|
const waitTime = 90_000;
|
||
|
|
console.log(`You have ${waitTime / 1000} seconds to complete the manual login...`);
|
||
|
|
await page.waitForTimeout(waitTime);
|
||
|
|
|
||
|
|
// Save the session
|
||
|
|
await page.context().storageState({ path: 'myGoogleAuth.json' });
|
||
|
|
console.log('Session saved in myGoogleAuth.json');
|
||
|
|
|
||
|
|
await browser.close();
|