From cee3c2ee22665d516c5da23cf5212d8cfa91b2b3 Mon Sep 17 00:00:00 2001 From: Lawrence Onah Date: Tue, 13 Dec 2022 15:39:54 +0100 Subject: [PATCH 1/2] get chrome executable path based on the platform --- legacy/src/openai-auth.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/legacy/src/openai-auth.ts b/legacy/src/openai-auth.ts index 74a21515..21f41267 100644 --- a/legacy/src/openai-auth.ts +++ b/legacy/src/openai-auth.ts @@ -1,4 +1,5 @@ import delay from 'delay' +import { platform } from 'os' import { type Browser, type Page, @@ -125,15 +126,26 @@ export async function getOpenAIAuth({ * recognizes it and blocks access. */ export async function getBrowser(launchOptions?: PuppeteerLaunchOptions) { - const macChromePath = - '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' - return puppeteer.launch({ headless: false, args: ['--no-sandbox', '--exclude-switches', 'enable-automation'], ignoreHTTPSErrors: true, - // executablePath: executablePath() - executablePath: macChromePath, + executablePath: executablePath(), ...launchOptions }) } + +/** + * Get the correct path to chrome's executable + * defaults to the path for macOs + */ +const executablePath = (): string => { + switch (platform()) { + case 'win32': + return 'C:\\ProgramFiles\\Google\\Chrome\\Application\\chrome.exe' + case 'linux': + return '/usr/bin/google-chrome-stable' + default: + return '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' + } +} From 0ceef39667c3449481eeeaf0c3d2aba41f0b5b0c Mon Sep 17 00:00:00 2001 From: Lawrence Onah Date: Tue, 13 Dec 2022 20:56:34 +0100 Subject: [PATCH 2/2] fix chrome executable path on linux --- legacy/src/openai-auth.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/legacy/src/openai-auth.ts b/legacy/src/openai-auth.ts index 21f41267..5146947d 100644 --- a/legacy/src/openai-auth.ts +++ b/legacy/src/openai-auth.ts @@ -1,5 +1,6 @@ +import * as fs from 'fs' +import * as os from 'os' import delay from 'delay' -import { platform } from 'os' import { type Browser, type Page, @@ -137,15 +138,22 @@ export async function getBrowser(launchOptions?: PuppeteerLaunchOptions) { /** * Get the correct path to chrome's executable - * defaults to the path for macOs */ const executablePath = (): string => { - switch (platform()) { + switch (os.platform()) { case 'win32': return 'C:\\ProgramFiles\\Google\\Chrome\\Application\\chrome.exe' - case 'linux': - return '/usr/bin/google-chrome-stable' - default: + case 'darwin': return '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' + default: + /** + * Since two (2) separate chrome releases exists on linux + * we first do a check to ensure we're executing the right one. + */ + const chromeExists = fs.existsSync('/usr/bin/google-chrome') + + return chromeExists + ? '/usr/bin/google-chrome' + : '/usr/bin/google-chrome-stable' } }