Skip to content

Commit 75e7b71

Browse files
authored
fix #594: group join fails due to timeout or broken selector (#604)
1 parent 15aab18 commit 75e7b71

File tree

1 file changed

+52
-9
lines changed

1 file changed

+52
-9
lines changed

packages/core/src/linkedinGroups.ts

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -576,23 +576,55 @@ async function executeJoinGroup(
576576

577577
const joinRegex = buildLocalizedRegex(
578578
runtime.selectorLocale,
579-
["Join"],
580-
["Deltag", "Bliv medlem"],
579+
["Join", "Request to join"],
580+
["Deltag", "Bliv medlem", "Anmod om at deltage", "Anmod om at blive medlem"],
581581
{ exact: true }
582582
);
583583
const joinButton = page.getByRole("button", {
584584
name: joinRegex
585585
}).first();
586+
587+
const isJoinButtonVisible = await joinButton.isVisible().catch(() => false);
588+
if (!isJoinButtonVisible) {
589+
const bodyTextPre = await page.locator("body").innerText().catch(() => "");
590+
if (/requested to join/iu.test(bodyTextPre)) {
591+
return {
592+
ok: true,
593+
result: {
594+
status: "group_join_requested",
595+
group_id: groupId,
596+
group_url: groupUrl
597+
},
598+
artifacts: []
599+
};
600+
}
601+
if (/joined group:|start a post in this group/iu.test(bodyTextPre)) {
602+
return {
603+
ok: true,
604+
result: {
605+
status: "group_joined",
606+
group_id: groupId,
607+
group_url: groupUrl
608+
},
609+
artifacts: []
610+
};
611+
}
612+
613+
throw new LinkedInBuddyError(
614+
"UI_CHANGED_SELECTOR_FAILED",
615+
"Could not locate Join button for group.",
616+
{ group_id: groupId, group_url: groupUrl }
617+
);
618+
}
619+
586620
await joinButton.click({ timeout: 5_000 });
587621

588622
await waitForCondition(async () => {
589-
const joinVisible = await page
590-
.getByRole("button", {
591-
name: joinRegex
592-
})
593-
.first()
594-
.isVisible()
595-
.catch(() => false);
623+
if (await isDialogVisible(page)) {
624+
return true;
625+
}
626+
627+
const joinVisible = await joinButton.isVisible().catch(() => false);
596628
if (!joinVisible) {
597629
return true;
598630
}
@@ -601,6 +633,17 @@ async function executeJoinGroup(
601633
return /requested to join|joined group:/iu.test(bodyText);
602634
}, 8_000);
603635

636+
if (await isDialogVisible(page)) {
637+
// Dismiss the dialog if possible to avoid state bleeding
638+
await page.getByRole("button", { name: buildLocalizedRegex(runtime.selectorLocale, ["Close", "Dismiss"], ["Luk", "Afvis"]) }).first().click().catch(() => {});
639+
640+
throw new LinkedInBuddyError(
641+
"ACTION_PRECONDITION_FAILED",
642+
"Group requires answering questions to join.",
643+
{ group_id: groupId, group_url: groupUrl }
644+
);
645+
}
646+
604647
const bodyText = await page.locator("body").innerText().catch(() => "");
605648
const status = /requested to join/iu.test(bodyText)
606649
? "group_join_requested"

0 commit comments

Comments
 (0)