-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 🐛 fixed changed amazon selectors
closes #221
- Loading branch information
Showing
3 changed files
with
688 additions
and
490 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,87 @@ | ||
import puppeteer, { Browser, Page } from "puppeteer"; | ||
import * as fs from 'fs'; | ||
import * as fs from "fs"; | ||
|
||
export { Browser, Page }; | ||
|
||
export class Puppeteer { | ||
public browser: Browser; | ||
private debug: boolean; | ||
private arguments: string[]; | ||
public browser: Browser; | ||
private debug: boolean; | ||
private arguments: string[]; | ||
|
||
constructor(debug: boolean, pupeteerArgs: string[]){ | ||
this.debug = debug; | ||
this.arguments = pupeteerArgs; | ||
} | ||
constructor(debug: boolean, pupeteerArgs: string[]) { | ||
this.debug = debug; | ||
this.arguments = pupeteerArgs; | ||
} | ||
|
||
public async setup(): Promise<Browser> { | ||
this.browser = await puppeteer.launch({ headless: `new`, args: this.arguments, dumpio: false, devtools: this.debug, executablePath: this.getExecutablePath() }); | ||
return this.browser; | ||
} | ||
public async setup(): Promise<Browser> { | ||
const headless = this.debug ? false : `new`; | ||
this.browser = await puppeteer.launch({ | ||
headless, | ||
args: this.arguments, | ||
dumpio: false, | ||
devtools: this.debug, | ||
executablePath: this.getExecutablePath(), | ||
}); | ||
return this.browser; | ||
} | ||
|
||
private getExecutablePath(): string { | ||
return this.locateChrome(); | ||
} | ||
private getExecutablePath(): string { | ||
return this.locateChrome(); | ||
} | ||
|
||
private locateChrome(): string { | ||
private locateChrome(): string { | ||
let paths: string[]; | ||
|
||
let paths: string[]; | ||
switch (process.platform) { | ||
case `darwin`: | ||
paths = [ | ||
`/Applications/Google Chrome.app/Contents/MacOS/Google Chrome`, | ||
`/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary`, | ||
`/Applications/Chromium.app/Contents/MacOS/Chromium`, | ||
`/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge`, | ||
`/usr/bin/google-chrome-stable`, | ||
`/usr/bin/google-chrome`, | ||
`/usr/bin/chromium`, | ||
`/usr/bin/chromium-browser`, | ||
]; | ||
break; | ||
|
||
case `win32`: | ||
paths = [ | ||
process.env[`LocalAppData`] + `/Google/Chrome/Application/chrome.exe`, | ||
process.env[`ProgramFiles`] + `/Google/Chrome/Application/chrome.exe`, | ||
process.env[`ProgramFiles(x86)`] + | ||
`/Google/Chrome/Application/chrome.exe`, | ||
process.env[`LocalAppData`] + `/Chromium/Application/chrome.exe`, | ||
process.env[`ProgramFiles`] + `/Chromium/Application/chrome.exe`, | ||
process.env[`ProgramFiles(x86)`] + `/Chromium/Application/chrome.exe`, | ||
process.env[`ProgramFiles(x86)`] + | ||
`/Microsoft/Edge/Application/msedge.exe`, | ||
process.env[`ProgramFiles`] + | ||
`/Microsoft/Edge/Application/msedge.exe`, | ||
]; | ||
break; | ||
default: | ||
paths = [ | ||
`/usr/bin/google-chrome-stable`, | ||
`/usr/bin/google-chrome`, | ||
`/usr/bin/chromium`, | ||
`/usr/bin/chromium-browser`, | ||
`/snap/bin/chromium`, | ||
]; | ||
} | ||
|
||
switch(process.platform) { | ||
case `darwin`: | ||
paths = [ | ||
`/Applications/Google Chrome.app/Contents/MacOS/Google Chrome`, | ||
`/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary`, | ||
`/Applications/Chromium.app/Contents/MacOS/Chromium`, | ||
`/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge`, | ||
`/usr/bin/google-chrome-stable`, | ||
`/usr/bin/google-chrome`, | ||
`/usr/bin/chromium`, | ||
`/usr/bin/chromium-browser` | ||
]; | ||
break; | ||
|
||
case `win32`: | ||
paths = [ | ||
process.env[`LocalAppData`] + `/Google/Chrome/Application/chrome.exe`, | ||
process.env[`ProgramFiles`] + `/Google/Chrome/Application/chrome.exe`, | ||
process.env[`ProgramFiles(x86)`] + `/Google/Chrome/Application/chrome.exe`, | ||
process.env[`LocalAppData`] + `/Chromium/Application/chrome.exe`, | ||
process.env[`ProgramFiles`] + `/Chromium/Application/chrome.exe`, | ||
process.env[`ProgramFiles(x86)`] + `/Chromium/Application/chrome.exe`, | ||
process.env[`ProgramFiles(x86)`] + `/Microsoft/Edge/Application/msedge.exe`, | ||
process.env[`ProgramFiles`] + `/Microsoft/Edge/Application/msedge.exe`, | ||
]; | ||
break; | ||
default: | ||
paths = [ | ||
`/usr/bin/google-chrome-stable`, | ||
`/usr/bin/google-chrome`, | ||
`/usr/bin/chromium`, | ||
`/usr/bin/chromium-browser`, | ||
`/snap/bin/chromium`, | ||
]; | ||
for (const path of paths) { | ||
try { | ||
fs.accessSync(path); | ||
return path; | ||
} catch (err) { | ||
if (err.code !== `ENOENT`) { | ||
throw err; | ||
} | ||
|
||
for (const path of paths) { | ||
try { | ||
fs.accessSync(path); | ||
return path; | ||
} catch (err) { | ||
if (err.code !== `ENOENT`) { | ||
throw err; | ||
} | ||
continue; | ||
} | ||
} | ||
return null; | ||
continue; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.