From 7826796bfdf3768b29aae01b5798c2c11cace136 Mon Sep 17 00:00:00 2001 From: Lawrence Onah Date: Tue, 13 Dec 2022 20:56:34 +0100 Subject: [PATCH] fix chrome executable path on linux --- src/openai-auth.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/openai-auth.ts b/src/openai-auth.ts index 21f4126..5146947 100644 --- a/src/openai-auth.ts +++ b/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' } }