fix: search frames for Continue /apply/ link when page.$() misses it

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-06 10:59:41 -08:00
parent 46c84bf28a
commit 1e67c930db

View File

@@ -114,10 +114,18 @@ export async function apply(page, job, formFiller) {
await page.evaluate(() => window.scrollTo(0, 300)).catch(() => {});
let eaBtn = await page.waitForSelector(LINKEDIN_APPLY_BUTTON_SELECTOR, { timeout: 12000, state: 'attached' }).catch(() => null);
// Fallback: LinkedIn shows plain "Continue" when a draft exists (span inside an <a>)
// Find the parent <a> link and click that, or navigate to the apply URL
// Fallback: LinkedIn shows plain "Continue" when a draft exists (span > span > a)
// The <a> has href containing /apply/ — click it to resume the draft
if (!eaBtn) {
const applyLink = await page.$(`a[href*="/apply/"]`);
// page.$() pierces shadow DOM; also check via evaluate in each frame
let applyLink = await page.$(`a[href*="/apply/"]`);
if (!applyLink) {
// Search frames directly (shadow DOM may block page.$)
for (const frame of page.frames()) {
applyLink = await frame.$(`a[href*="/apply/"]`).catch(() => null);
if (applyLink) break;
}
}
if (applyLink) {
const text = await applyLink.evaluate(el => (el.innerText || '').trim()).catch(() => '');
if (/continue/i.test(text)) {