Skip to content

Commit

Permalink
Use Installed browser and Handle download issue
Browse files Browse the repository at this point in the history
  • Loading branch information
vikas5914 committed Oct 5, 2023
1 parent b5a0cc5 commit 08e11fc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
16 changes: 13 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const saveProgress = async (page) => {
const browser = await chromium.launchPersistentContext(path.resolve(userDataDir), {
headless,
acceptDownloads: true,
channel: 'chromium', // possible values: chrome, msedge and chromium
args: ['--no-sandbox', '--disable-setuid-sandbox']
})

Expand Down Expand Up @@ -88,12 +89,21 @@ const saveProgress = async (page) => {
})()

const downloadPhoto = async (page, overwrite = false) => {
const downloadPromise = page.waitForEvent('download')
const downloadPromise = page.waitForEvent('download', {
timeout: 30000
})

await page.keyboard.down('Shift')
await page.keyboard.press('KeyD')

const download = await downloadPromise
let download
try {
download = await downloadPromise
} catch (error) {
console.log('There was an error while downloading the photo, Skipping...', page.url())
return
}

const temp = await download.path()
const fileName = await download.suggestedFilename()

Expand All @@ -108,7 +118,7 @@ const downloadPhoto = async (page, overwrite = false) => {
const data = await page.request.get(page.url())
const html = await data.text()

const regex = /aria-label="Photo - ([^"]+)"/
const regex = /aria-label="(Photo . Landscape|Photo . Portrait|Video . Landscape|Video . Portrait|Video|Photo) . ([^"]+)"/
const match = regex.exec(html)

if (match) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const userDataDir = './session';
(async () => {
const browser = await chromium.launchPersistentContext(path.resolve(userDataDir), {
headless: false,
channel: 'chrome', // possible values: chrome, msedge and chromium
args: ['--no-sandbox', '--disable-setuid-sandbox']
})
const page = await browser.newPage()
Expand Down

0 comments on commit 08e11fc

Please sign in to comment.