Skip to content

Commit

Permalink
Addition of Microsoft Login.
Browse files Browse the repository at this point in the history
  • Loading branch information
optionsx authored Dec 18, 2022
1 parent c331c73 commit 242ea3d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/chatgpt-api-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
protected _debug: boolean
protected _minimize: boolean
protected _isGoogleLogin: boolean
protected _isWindowsLogin: boolean
protected _captchaToken: string
protected _accessToken: string

Expand All @@ -46,6 +47,9 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
/** @defaultValue `false` **/
isGoogleLogin?: boolean

/** @defaultValue `false` **/
isWindowsLogin?: boolean

/** @defaultValue `true` **/
minimize?: boolean

Expand All @@ -63,6 +67,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
markdown = true,
debug = false,
isGoogleLogin = false,
isWindowsLogin = false,
minimize = true,
captchaToken,
executablePath
Expand All @@ -74,6 +79,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
this._markdown = !!markdown
this._debug = !!debug
this._isGoogleLogin = !!isGoogleLogin
this._isWindowsLogin = !!isWindowsLogin
this._minimize = !!minimize
this._captchaToken = captchaToken
this._executablePath = executablePath
Expand Down Expand Up @@ -124,7 +130,8 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
password: this._password,
browser: this._browser,
page: this._page,
isGoogleLogin: this._isGoogleLogin
isGoogleLogin: this._isGoogleLogin,
isWindowsLogin: this._isWindowsLogin
})
} catch (err) {
if (this._browser) {
Expand All @@ -137,7 +144,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
throw err
}

if (!this.isChatPage || this._isGoogleLogin) {
if (!this.isChatPage || this._isGoogleLogin || this._isWindowsLogin) {
await this._page.goto(CHAT_PAGE_URL, {
waitUntil: 'networkidle2'
})
Expand Down
20 changes: 19 additions & 1 deletion src/openai-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export async function getOpenAIAuth({
page,
timeoutMs = 2 * 60 * 1000,
isGoogleLogin = false,
isWindowsLogin = false,
captchaToken = process.env.CAPTCHA_TOKEN,
nopechaKey = process.env.NOPECHA_KEY,
executablePath
Expand All @@ -63,6 +64,7 @@ export async function getOpenAIAuth({
page?: Page
timeoutMs?: number
isGoogleLogin?: boolean
isWindowsLogin?: boolean
captchaToken?: string
nopechaKey?: string
executablePath?: string
Expand Down Expand Up @@ -132,6 +134,23 @@ export async function getOpenAIAuth({
await page.waitForSelector('input[type="password"]', { visible: true })
await page.type('input[type="password"]', password, { delay: 10 })
submitP = () => page.keyboard.press('Enter')
} else if (isWindowsLogin) {
await page.click('button[data-provider="windowslive"]')
await page.waitForSelector('input[type="email"]')
await page.type('input[type="email"]', email, { delay: 10 })
await Promise.all([
page.waitForNavigation(),
await page.keyboard.press('Enter')
])
await delay(1500)
await page.waitForSelector('input[type="password"]', { visible: true })
await page.type('input[type="password"]', password, { delay: 10 })
submitP = () => page.keyboard.press('Enter')
await Promise.all([
page.waitForNavigation(),
await page.keyboard.press('Enter')
])
await delay(1000)
} else {
await page.waitForSelector('#username')
await page.type('#username', email, { delay: 20 })
Expand Down Expand Up @@ -293,7 +312,6 @@ export async function getBrowser(
const page = (await browser.pages())[0] || (await browser.newPage())
await page.goto(`https://nopecha.com/setup#${nopechaKey}`)
await delay(1000)

try {
const page3 = await browser.newPage()
await page.close()
Expand Down

0 comments on commit 242ea3d

Please sign in to comment.