Currently, I am faced with the challenge of automating rate-limit requests using a playwright automation script.
The issue arises when the script keeps attempting to sign up with the email
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fe8a9b8d8acebe9b869f938e929bd09d9193">[email protected]</a>
, resulting in an error indicating that the email is already in use.
Despite my efforts to implement async...await
correctly with the for...loop
, it seems like something is not working as intended.
import { chromium } from 'playwright'
async function main() {
const browser = await chromium.launch({ headless: false })
const page = await browser.newPage()
for (let i = 0; i < 20; i++) {
await page.goto('http://localhost:3000/signup')
await page.waitForLoadState('domcontentloaded')
await page.fill('input[name="email"]', `test${i}@example.com`)
await page.click('button[type="submit"]')
await page.waitForURL('http://localhost:3000/verify-email')
console.log(i)
}
await page.close()
await browser.close()
}
main()
I also attempted the commented code section above, but it did not yield the desired results either.
When examining the response from my server script, it displays:
{ email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a2d6c7d1d692e2c7dac3cfd2cec78cc1cdcf">[email protected]</a>' }
{ user: [], unique: true }
{ email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8afeeff9febacaeff2ebe7fae6efa4e9e5e7">[email protected]</a>' }
{
user: [
{
id: '01HNPK1GRM5ZHWXZBV1K2R3A9B',
email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6f1b0a1c1b5f2f0a170e021f030a410c0002">[email protected]</a>',
emailVerified: 0
}
],
unique: false
}
The server checks for unique emails, displaying unique: true
initially but then strangely returns unique: false
.
This is unexpected given the use of for...loop
along with async...await
.
The expected output should resemble:
{ email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fe8a9b8d8acebe9b869f938e929bd09d9193">[email protected]</a>' }
{ user: [], unique: true }
{ email: '[email protected]' }
{ user: [], unique: true }
What could be going wrong in this scenario?
It's worth mentioning that similar issues were encountered while using Puppeteer as well:
import puppeteer from 'puppeteer'
async function main() {
const browser = await puppeteer.launch({
headless: false,
})
const page = await browser.newPage()
for (let i = 0; i < 20; i++) {
await page.goto('http://localhost:3000/signup')
await page.type('input[name="email"]', `test${i}@example.com`)
await page.click('button[type="submit"]')
await page.waitForNavigation()
console.log(i)
}
await page.close()
await browser.close()
}
Furthermore, the technology stack involves the utilization of React Server Actions within Next.js 14 -> https://github.com/deadcoder0904/next-14-lucia-v3-sqlite-drizzle-conform-zod-email-verification-otp-server-actions/