Skip to content

Commit 08e11fc

Browse files
committed
Use Installed browser and Handle download issue
1 parent b5a0cc5 commit 08e11fc

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const saveProgress = async (page) => {
4141
const browser = await chromium.launchPersistentContext(path.resolve(userDataDir), {
4242
headless,
4343
acceptDownloads: true,
44+
channel: 'chromium', // possible values: chrome, msedge and chromium
4445
args: ['--no-sandbox', '--disable-setuid-sandbox']
4546
})
4647

@@ -88,12 +89,21 @@ const saveProgress = async (page) => {
8889
})()
8990

9091
const downloadPhoto = async (page, overwrite = false) => {
91-
const downloadPromise = page.waitForEvent('download')
92+
const downloadPromise = page.waitForEvent('download', {
93+
timeout: 30000
94+
})
9295

9396
await page.keyboard.down('Shift')
9497
await page.keyboard.press('KeyD')
9598

96-
const download = await downloadPromise
99+
let download
100+
try {
101+
download = await downloadPromise
102+
} catch (error) {
103+
console.log('There was an error while downloading the photo, Skipping...', page.url())
104+
return
105+
}
106+
97107
const temp = await download.path()
98108
const fileName = await download.suggestedFilename()
99109

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

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

114124
if (match) {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const userDataDir = './session';
99
(async () => {
1010
const browser = await chromium.launchPersistentContext(path.resolve(userDataDir), {
1111
headless: false,
12+
channel: 'chrome', // possible values: chrome, msedge and chromium
1213
args: ['--no-sandbox', '--disable-setuid-sandbox']
1314
})
1415
const page = await browser.newPage()

0 commit comments

Comments
 (0)