Poll for submission success instead of single check

After clicking submit, poll up to 4 times (2.5s + 3x2s = ~8.5s total)
for success text or form disappearance. Handles invisible reCAPTCHA
verification delay. Stops early on validation errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-06 21:11:50 -08:00
parent 5caa063175
commit 0118254046
2 changed files with 30 additions and 21 deletions

View File

@@ -20,9 +20,12 @@ export async function apply(page, job, formFiller) {
await page.$('input[type="file"][name*="resume"]') ||
await page.$('input[type="file"]');
if (fileInput) {
const hasFile = await fileInput.evaluate(el => !!el.value);
if (!hasFile) {
await fileInput.setInputFiles(formFiller.profile.resume_path).catch(() => {});
await page.waitForTimeout(1500);
}
}
},
});
}

View File

@@ -149,12 +149,15 @@ async function fillAndSubmit(page, job, formFiller, meta, opts) {
if (hasSubmit) {
await submitBtn.click();
await page.waitForTimeout(SUBMIT_WAIT);
// Wait for submission — poll for success or form disappearance
// (invisible reCAPTCHA + server round-trip can take several seconds)
const verifySelector = opts.verifySelector || 'form button[type="submit"]:not([disabled])';
const postSubmit = await page.evaluate((vs) => {
let postSubmit = { hasSuccess: false, hasForm: true, validationErrors: [] };
for (let wait = 0; wait < 4; wait++) {
await page.waitForTimeout(wait === 0 ? SUBMIT_WAIT : 2000);
postSubmit = await page.evaluate((vs) => {
const text = (document.body.innerText || '').toLowerCase();
// Check for validation errors (red text, error messages)
const errorEls = document.querySelectorAll('[class*="error"], [class*="invalid"], [role="alert"]');
const validationErrors = Array.from(errorEls)
.map(el => el.innerText?.trim())
@@ -172,6 +175,9 @@ async function fillAndSubmit(page, job, formFiller, meta, opts) {
if (postSubmit.hasSuccess || !postSubmit.hasForm) {
return { status: 'submitted', meta };
}
// Stop polling if validation errors appeared (form didn't submit)
if (postSubmit.validationErrors.length > 0) break;
}
return {
status: 'incomplete', meta,