Skip to content

Commit

Permalink
Merge 638fa4e into 872c525
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Apr 22, 2024
2 parents 872c525 + 638fa4e commit eadb3df
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
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>')
})

0 comments on commit eadb3df

Please sign in to comment.