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

View File

@@ -149,28 +149,34 @@ async function fillAndSubmit(page, job, formFiller, meta, opts) {
if (hasSubmit) { if (hasSubmit) {
await submitBtn.click(); 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 verifySelector = opts.verifySelector || 'form button[type="submit"]:not([disabled])';
const postSubmit = await page.evaluate((vs) => { let postSubmit = { hasSuccess: false, hasForm: true, validationErrors: [] };
const text = (document.body.innerText || '').toLowerCase(); for (let wait = 0; wait < 4; wait++) {
// Check for validation errors (red text, error messages) await page.waitForTimeout(wait === 0 ? SUBMIT_WAIT : 2000);
const errorEls = document.querySelectorAll('[class*="error"], [class*="invalid"], [role="alert"]'); postSubmit = await page.evaluate((vs) => {
const validationErrors = Array.from(errorEls) const text = (document.body.innerText || '').toLowerCase();
.map(el => el.innerText?.trim()) const errorEls = document.querySelectorAll('[class*="error"], [class*="invalid"], [role="alert"]');
.filter(t => t && t.length < 200) const validationErrors = Array.from(errorEls)
.slice(0, 3); .map(el => el.innerText?.trim())
return { .filter(t => t && t.length < 200)
hasSuccess: text.includes('application submitted') || text.includes('successfully applied') || .slice(0, 3);
text.includes('thank you') || text.includes('application received') || return {
text.includes('application has been') || text.includes('we received your'), hasSuccess: text.includes('application submitted') || text.includes('successfully applied') ||
hasForm: !!document.querySelector(vs), text.includes('thank you') || text.includes('application received') ||
validationErrors, text.includes('application has been') || text.includes('we received your'),
}; hasForm: !!document.querySelector(vs),
}, verifySelector).catch(() => ({ hasSuccess: false, hasForm: false, validationErrors: [] })); validationErrors,
};
}, verifySelector).catch(() => ({ hasSuccess: false, hasForm: false, validationErrors: [] }));
if (postSubmit.hasSuccess || !postSubmit.hasForm) { if (postSubmit.hasSuccess || !postSubmit.hasForm) {
return { status: 'submitted', meta }; return { status: 'submitted', meta };
}
// Stop polling if validation errors appeared (form didn't submit)
if (postSubmit.validationErrors.length > 0) break;
} }
return { return {