bug fix + ui improvements

This commit is contained in:
Daniel
2023-07-24 10:06:24 -04:00
parent cbf53f6e30
commit 1086e22451
3 changed files with 27 additions and 21 deletions
+10 -4
View File
@@ -7,12 +7,12 @@ export default async function archive(
collectionId: number,
linkId: number
) {
const browser = await chromium.launch();
const browser = await chromium.launch({ headless: false });
const context = await browser.newContext(devices["Desktop Chrome"]);
const page = await context.newPage();
try {
await page.goto(url, { waitUntil: "domcontentloaded", timeout: 300000 });
await page.goto(url, { waitUntil: "domcontentloaded" });
await autoScroll(page);
@@ -53,7 +53,13 @@ export default async function archive(
const autoScroll = async (page: Page) => {
await page.evaluate(async () => {
await new Promise<void>((resolve, reject) => {
const timeoutPromise = new Promise<void>((_, reject) => {
setTimeout(() => {
reject(new Error("Auto scroll took too long (more than 10 seconds)."));
}, 20000);
});
const scrollingPromise = new Promise<void>((resolve) => {
let totalHeight = 0;
let distance = 100;
let scrollDown = setInterval(() => {
@@ -68,6 +74,6 @@ const autoScroll = async (page: Page) => {
}, 100);
});
await new Promise((r) => setTimeout(r, 2000));
await Promise.race([scrollingPromise, timeoutPromise]);
});
};