Skip to content

Commit

Permalink
get chrome executable path based on the platform
Browse files Browse the repository at this point in the history
  • Loading branch information
kodjunkie committed Dec 13, 2022
1 parent 6fb1ff9 commit 87b168d
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/openai-auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import delay from 'delay'
import { platform } from 'os'
import {
type Browser,
type Page,
Expand Down Expand Up @@ -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'
}
}

0 comments on commit 87b168d

Please sign in to comment.