Skip to content

Commit

Permalink
Update puppeteer (#60)
Browse files Browse the repository at this point in the history
* Update puppeteer

* Replace deprecated waitForXPath

* Replace deprecated waitForTimeOut

* Clean up
  • Loading branch information
Jym77 authored Jul 29, 2024
1 parent 65a5f56 commit 7382cf9
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 167 deletions.
5 changes: 4 additions & 1 deletion packages/alfa-cli/src/alfa/command/scrape/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ export const Flags = {

awaitDuration: Flag.integer(
"await-duration",
"The duration to wait before considering the page loaded."
`The duration to wait before considering the page loaded.
Note that waiting for fixed durations creates race conditions and is less
reliable than other awaiters. This flag must be used with caution, especially
in settings where reliability is important (production, automated tests, …)`
)
.type("milliseconds")
.optional(),
Expand Down
2 changes: 1 addition & 1 deletion packages/alfa-puppeteer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@siteimprove/alfa-dom": "^0.88.0",
"@siteimprove/alfa-http": "^0.88.0",
"@siteimprove/alfa-web": "^0.88.0",
"puppeteer": "^19.9.1"
"puppeteer": "^22.14.0"
},
"peerDependencies": {
"@siteimprove/alfa-device": "^0.88.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/alfa-scraper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@siteimprove/alfa-time": "^0.88.0",
"@siteimprove/alfa-url": "^0.88.0",
"@siteimprove/alfa-web": "^0.88.0",
"puppeteer": "^19.9.1"
"puppeteer": "^22.14.0"
},
"devDependencies": {
"@siteimprove/alfa-test": "^0.88.0"
Expand Down
6 changes: 4 additions & 2 deletions packages/alfa-scraper/src/awaiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ export namespace Awaiter {
const error = await after(page, timeout);

if (error.isNone()) {
await page.waitForTimeout(duration);
await new globalThis.Promise(function (resolve) {
setTimeout(resolve, duration);
});
}

return error;
Expand Down Expand Up @@ -144,7 +146,7 @@ export namespace Awaiter {
export function xpath(expression: string): Awaiter {
return async (page, timeout) => {
try {
await page.waitForXPath(expression, {
await page.waitForSelector("xpath/" + expression, {
timeout: timeout.remaining(),
});

Expand Down
Loading

0 comments on commit 7382cf9

Please sign in to comment.