Skip to content

Commit

Permalink
chore: Replace deprecated waitFor with waitForTimeout (#441)
Browse files Browse the repository at this point in the history
* replacing deprecated waitFor for waitForTimeout

* injecting waitForTimeout 4 older v. compatibility

* 2nd

Co-authored-by: Josep Alsina <josepalsinasio@gmail.com>
  • Loading branch information
josep11 and Josep Alsina committed Mar 14, 2021
1 parent 1575f1a commit 1e8840c
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 21 deletions.
4 changes: 2 additions & 2 deletions packages/puppeteer-extra-plugin-adblocker/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ puppeteer.launch({ headless: true }).then(async (browser) => {
// Visit a page, ads are blocked automatically!
await page.goto('https://www.google.com/search?q=rent%20a%20car')

await page.waitFor(5 * 1000)
await page.waitForTimeout(5 * 1000)
await page.screenshot({ path: 'response.png', fullPage: true })

console.log(`All done, check the screenshots. ✨`)
Expand All @@ -69,7 +69,7 @@ puppeteer
.then(async (browser) => {
const page = await browser.newPage()
await page.goto('https://www.vanityfair.com')
await page.waitFor(60 * 1000)
await page.waitForTimeout(60 * 1000)
await browser.close()
})
```
Expand Down
2 changes: 1 addition & 1 deletion packages/puppeteer-extra-plugin-devtools/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ puppeteer.launch().then(async browser => {

const page = await browser.newPage()
await page.goto('https://www.google.com')
await page.waitFor(60 * 1000)
await page.waitForTimeout(60 * 1000)
browser.close()
})
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ test('regression: new method will not break recaptcha popup', async t => {
.launch({ headless: true })
const page = await browser.newPage()

page.waitForTimeout = page.waitForTimeout || page.waitFor

await page.goto('https://www.fbdemo.com/invisible-captcha/index.html')

await page.type('#tswname', 'foo')
Expand All @@ -272,7 +274,8 @@ test('regression: new method will not break recaptcha popup', async t => {
'In the depth of winter, I finally learned that within me there lay an invincible summer.'
)
await page.click('#tswsubmit')
await page.waitFor(1000)
await page.waitForTimeout(1000)


const { hasRecaptchaPopup } = await page.evaluate(() => {
const hasRecaptchaPopup = !!document.querySelectorAll(
Expand All @@ -290,11 +293,12 @@ test('regression: old method indeed did break recaptcha popup', async t => {
const browser = await vanillaPuppeteer.launch({ headless: true })
const page = await browser.newPage()

page.waitForTimeout = page.waitForTimeout || page.waitFor
// Old method
await page.evaluateOnNewDocument(() => {
// eslint-disable-next-line
Object.defineProperty(HTMLIFrameElement.prototype, 'contentWindow', {
get: function() {
get: function () {
return window
}
})
Expand All @@ -309,7 +313,7 @@ test('regression: old method indeed did break recaptcha popup', async t => {
'In the depth of winter, I finally learned that within me there lay an invincible summer.'
)
await page.click('#tswsubmit')
await page.waitFor(1000)
await page.waitForTimeout(1000)

const { hasRecaptchaPopup } = await page.evaluate(() => {
const hasRecaptchaPopup = !!document.querySelectorAll(
Expand Down
4 changes: 2 additions & 2 deletions packages/puppeteer-extra-plugin-stealth/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ puppeteer.launch({ headless: true }).then(async browser => {
console.log('Running tests..')
const page = await browser.newPage()
await page.goto('https://bot.sannysoft.com')
await page.waitFor(5000)
await page.waitForTimeout(5000)
await page.screenshot({ path: 'testresult.png', fullPage: true })
await browser.close()
console.log(`All done, check the screenshot. ✨`)
Expand All @@ -59,7 +59,7 @@ puppeteer
.then(async browser => {
const page = await browser.newPage()
await page.goto('https://bot.sannysoft.com')
await page.waitFor(5000)
await page.waitForTimeout(5000)
await page.screenshot({ path: 'stealth.png', fullPage: true })
await browser.close()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function main() {
const page = await browser.newPage()
await page.setViewport({ width: 800, height: 600 })
await page.goto('https://bot.sannysoft.com/')
await page.waitFor(5000)
await page.waitForTimeout(5000)
await page.screenshot({ path: screenshotPath, fullPage: true })

await browser.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async function main() {
const page = await browser.newPage()
await page.setViewport({ width: 800, height: 600 })
await page.goto('https://bot.sannysoft.com/')
await page.waitFor(5000)
await page.waitForTimeout(5000)
await page.screenshot({ path: screenshotPath, fullPage: true })

await browser.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function main() {
const page = await browser.newPage()
await page.setViewport({ width: 800, height: 600 })
await page.goto('https://bot.sannysoft.com/')
await page.waitFor(5000)
await page.waitForTimeout(5000)
await page.screenshot({ path: screenshotPath, fullPage: true })

await browser.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
const page = await browser.newPage()
await page.setViewport({ width: 800, height: 600 })
await page.goto('https://bot.sannysoft.com/')
await page.waitFor(5000)
await page.waitForTimeout(5000)
await page.screenshot({ path: screenshotPath, fullPage: true })

await browser.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function main() {
const page = await browser.newPage()
await page.setViewport({ width: 800, height: 600 })
await page.goto('https://bot.sannysoft.com/')
await page.waitFor(5000)
await page.waitForTimeout(5000)
await page.screenshot({ path: screenshotPath, fullPage: true })

await browser.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async function main() {
const page = await browser.newPage()
await page.setViewport({ width: 800, height: 600 })
await page.goto('https://bot.sannysoft.com/')
await page.waitFor(5000)
await page.waitForTimeout(5000)
await page.screenshot({ path: screenshotPath, fullPage: true })

await browser.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function main() {
const page = await browser.newPage()
await page.setViewport({ width: 800, height: 600 })
await page.goto('https://bot.sannysoft.com/')
await page.waitFor(5000)
await page.waitForTimeout(5000)
await page.screenshot({ path: screenshotPath, fullPage: true })

await browser.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
const page = await browser.newPage()
await page.setViewport({ width: 800, height: 600 })
await page.goto('https://bot.sannysoft.com/')
await page.waitFor(5000)
await page.waitForTimeout(5000)
await page.screenshot({ path: screenshotPath, fullPage: true })

await browser.close()
Expand Down
10 changes: 5 additions & 5 deletions packages/puppeteer-extra/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ puppeteer.launch({ headless: true }).then(async browser => {

console.log(`Testing adblocker plugin..`)
await page.goto('https://www.vanityfair.com')
await page.waitFor(1000)
await page.waitForTimeout(1000)
await page.screenshot({ path: 'adblocker.png', fullPage: true })

console.log(`Testing the stealth plugin..`)
await page.goto('https://bot.sannysoft.com')
await page.waitFor(5000)
await page.waitForTimeout(5000)
await page.screenshot({ path: 'stealth.png', fullPage: true })

console.log(`All done, check the screenshots. ✨`)
Expand Down Expand Up @@ -88,7 +88,7 @@ puppeteer
.then(async browser => {
const page = await browser.newPage()
await page.goto('https://bot.sannysoft.com')
await page.waitFor(5000)
await page.waitForTimeout(5000)
await page.screenshot({ path: 'stealth.png', fullPage: true })
await browser.close()
})
Expand Down Expand Up @@ -160,7 +160,7 @@ puppeteer
.then(async browser => {
const page = await browser.newPage()
await page.goto('https://www.spacejam.com/archive/spacejam/movie/jam.htm')
await page.waitFor(10 * 1000)
await page.waitForTimeout(10 * 1000)
await browser.close()
})
```
Expand Down Expand Up @@ -254,7 +254,7 @@ const launch = async () => {
.then(async browser => {
const page = await browser.newPage()
await page.goto('https://www.spacejam.com/archive/spacejam/movie/jam.htm')
await page.waitFor(10 * 1000)
await page.waitForTimeout(10 * 1000)
await browser.close()
})
}
Expand Down

0 comments on commit 1e8840c

Please sign in to comment.