Skip to content

Commit

Permalink
fix(goto): abort page.goto after timeout (#580)
Browse files Browse the repository at this point in the history
* fix(goto): abort page.goto after timeout

I discovered there is no way to cancel `page.goto` unless you take care about it.

Long issue with several workarounds: puppeteer/puppeteer#3238

* v10.5.0-alpha.0
  • Loading branch information
Kikobeats committed May 5, 2024
1 parent b809f27 commit fe19832
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [10.5.0-alpha.0](https://github.com/microlinkhq/browserless/compare/v10.4.1...v10.5.0-alpha.0) (2024-04-22)

### Bug Fixes

* **goto:** abort page.goto after timeout ([638fa4e](https://github.com/microlinkhq/browserless/commit/638fa4efadf59ddde2cd772fbc2d012ae9535f68))

## [10.4.1](https://github.com/microlinkhq/browserless/compare/v10.4.0...v10.4.1) (2024-03-23)

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": [
"packages/*"
],
"version": "10.4.1",
"version": "10.5.0-alpha.0",
"command": {
"bootstrap": {
"npmClientArgs": [
Expand Down
4 changes: 4 additions & 0 deletions packages/browserless/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [10.5.0-alpha.0](https://github.com/microlinkhq/browserless/compare/v10.4.1...v10.5.0-alpha.0) (2024-04-22)

**Note:** Version bump only for package browserless

# [10.4.0](https://github.com/microlinkhq/browserless/compare/v10.3.0...v10.4.0) (2024-03-19)

**Note:** Version bump only for package browserless
Expand Down
8 changes: 4 additions & 4 deletions packages/browserless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "browserless",
"description": "The headless Chrome/Chromium performance driver for Node.js",
"homepage": "https://browserless.js.org",
"version": "10.4.0",
"version": "10.5.0-alpha.0",
"main": "src/index.js",
"author": {
"email": "hello@microlink.io",
Expand Down Expand Up @@ -32,9 +32,9 @@
],
"dependencies": {
"@browserless/errors": "^10.3.0",
"@browserless/goto": "^10.4.0",
"@browserless/pdf": "^10.4.0",
"@browserless/screenshot": "^10.4.0",
"@browserless/goto": "^10.5.0-alpha.0",
"@browserless/pdf": "^10.5.0-alpha.0",
"@browserless/screenshot": "^10.5.0-alpha.0",
"debug-logfmt": "~1.2.1",
"kill-process-group": "~1.0.7",
"p-reflect": "~2.1.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [10.5.0-alpha.0](https://github.com/microlinkhq/browserless/compare/v10.4.1...v10.5.0-alpha.0) (2024-04-22)

**Note:** Version bump only for package @browserless/cli

# [10.4.0](https://github.com/microlinkhq/browserless/compare/v10.3.0...v10.4.0) (2024-03-19)

**Note:** Version bump only for package @browserless/cli
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@browserless/cli",
"description": "CLI to interact with Browserless capabilities",
"homepage": "https://browserless.js.org",
"version": "10.4.0",
"version": "10.5.0-alpha.0",
"bin": {
"browserless": "src/index.js"
},
Expand Down Expand Up @@ -32,7 +32,7 @@
],
"dependencies": {
"beauty-error": "~1.2.18",
"browserless": "^10.4.0",
"browserless": "^10.5.0-alpha.0",
"dark-mode": "~3.0.0",
"dset": "~3.1.3",
"mri": "~1.2.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/function/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [10.5.0-alpha.0](https://github.com/microlinkhq/browserless/compare/v10.4.1...v10.5.0-alpha.0) (2024-04-22)

**Note:** Version bump only for package @browserless/function

# [10.4.0](https://github.com/microlinkhq/browserless/compare/v10.3.0...v10.4.0) (2024-03-19)

**Note:** Version bump only for package @browserless/function
Expand Down
4 changes: 2 additions & 2 deletions packages/function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@browserless/function",
"description": "Run abritrary JavaScript inside a browser sandbox",
"homepage": "https://browserless.js.org",
"version": "10.4.0",
"version": "10.5.0-alpha.0",
"main": "src/index.js",
"author": {
"email": "hello@microlink.io",
Expand Down Expand Up @@ -42,7 +42,7 @@
"devDependencies": {
"@browserless/test": "^10.3.0",
"ava": "5",
"browserless": "^10.4.0",
"browserless": "^10.5.0-alpha.0",
"lodash": "latest"
},
"engines": {
Expand Down
6 changes: 6 additions & 0 deletions packages/goto/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [10.5.0-alpha.0](https://github.com/microlinkhq/browserless/compare/v10.4.1...v10.5.0-alpha.0) (2024-04-22)

### Bug Fixes

* **goto:** abort page.goto after timeout ([638fa4e](https://github.com/microlinkhq/browserless/commit/638fa4efadf59ddde2cd772fbc2d012ae9535f68))

# [10.4.0](https://github.com/microlinkhq/browserless/compare/v10.3.0...v10.4.0) (2024-03-19)

### Performance Improvements
Expand Down
2 changes: 1 addition & 1 deletion packages/goto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@browserless/goto",
"description": "Go to a page aborting unnecessary requests",
"homepage": "https://browserless.js.org/#/?id=gotopage-options",
"version": "10.4.0",
"version": "10.5.0-alpha.0",
"main": "src/index.js",
"author": {
"email": "hello@microlink.io",
Expand Down
9 changes: 6 additions & 3 deletions packages/goto/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ module.exports = ({ defaultDevice = 'Macbook Pro 13', timeout: globalTimeout, ..
scripts,
scroll,
styles,
timeout = globalTimeout,
timeout,
timezone,
url,
username,
Expand All @@ -210,7 +210,7 @@ module.exports = ({ defaultDevice = 'Macbook Pro 13', timeout: globalTimeout, ..
...args
}
) => {
const baseTimeout = timeouts.base(globalTimeout)
const baseTimeout = timeouts.base(timeout || globalTimeout)
const actionTimeout = timeouts.action(baseTimeout)
const gotoTimeout = timeouts.goto(baseTimeout)

Expand Down Expand Up @@ -363,7 +363,10 @@ module.exports = ({ defaultDevice = 'Macbook Pro 13', timeout: globalTimeout, ..
const { value: response, reason: error } = await run({
fn: html
? page.setContent(html, { waitUntil, ...args })
: page.goto(url, { waitUntil, ...args }),
: Promise.race([
page.goto(url, { waitUntil, ...args }),
setTimeout(gotoTimeout).then(() => page._client().send('Page.stopLoading'))
]),
timeout: gotoTimeout,
debug: { fn: html ? 'html' : 'url', waitUntil }
})
Expand Down
11 changes: 11 additions & 0 deletions packages/goto/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,14 @@ test('handle page disconnections', async t => {

await intercept('chrome://version')
})

test('handle page.goto hanging', async t => {
const browserless = await getBrowserContext(t)

const html = await browserless.html('https://test-timeout.vercel.app/', {
timeout: 5000,
animations: true
})

t.is(html, '<html><head></head><body></body></html>')
})
4 changes: 4 additions & 0 deletions packages/pdf/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [10.5.0-alpha.0](https://github.com/microlinkhq/browserless/compare/v10.4.1...v10.5.0-alpha.0) (2024-04-22)

**Note:** Version bump only for package @browserless/pdf

# [10.4.0](https://github.com/microlinkhq/browserless/compare/v10.3.0...v10.4.0) (2024-03-19)

**Note:** Version bump only for package @browserless/pdf
Expand Down
4 changes: 2 additions & 2 deletions packages/pdf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@browserless/pdf",
"description": "Sensible good defaults for exporting a website as PDF",
"homepage": "https://browserless.js.org/#/?id=pdfurl-options",
"version": "10.4.0",
"version": "10.5.0-alpha.0",
"main": "src",
"repository": {
"directory": "packages/pdf",
Expand All @@ -24,7 +24,7 @@
"screen"
],
"dependencies": {
"@browserless/goto": "^10.4.0"
"@browserless/goto": "^10.5.0-alpha.0"
},
"engines": {
"node": ">= 12"
Expand Down
4 changes: 4 additions & 0 deletions packages/screenshot/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [10.5.0-alpha.0](https://github.com/microlinkhq/browserless/compare/v10.4.1...v10.5.0-alpha.0) (2024-04-22)

**Note:** Version bump only for package @browserless/screenshot

# [10.4.0](https://github.com/microlinkhq/browserless/compare/v10.3.0...v10.4.0) (2024-03-19)

### Performance Improvements
Expand Down
4 changes: 2 additions & 2 deletions packages/screenshot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@browserless/screenshot",
"description": "Take a clean screenshot of any website",
"homepage": "https://browserless.js.org/#/?id=screenshoturl-options",
"version": "10.4.0",
"version": "10.5.0-alpha.0",
"main": "src/index.js",
"author": {
"email": "hello@microlink.io",
Expand All @@ -28,7 +28,7 @@
"screenshot"
],
"dependencies": {
"@browserless/goto": "^10.4.0",
"@browserless/goto": "^10.5.0-alpha.0",
"@kikobeats/time-span": "~1.0.3",
"debug-logfmt": "~1.2.1",
"got": "~11.8.6",
Expand Down

0 comments on commit fe19832

Please sign in to comment.