coffeeinabit 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coffeeinabit",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "CoffeeInABit App",
5
5
  "main": "server.js",
6
6
  "type": "module",
@@ -38,7 +38,7 @@ async function detectConnectionStatus(page, username) {
38
38
  moreActionsSelectors = await getButtonByText(page, 'More actions', inMain);
39
39
  }
40
40
  if (moreActionsSelectors && (await moreActionsSelectors.isVisible())) {
41
- await moreActionsSelectors.click();
41
+ await clickWithRetries(moreActionsSelectors);
42
42
  await new Promise(resolve => setTimeout(resolve, Math.floor(Math.random() * 1000) + 500));
43
43
  }
44
44
  let removeConnectionButton = await getButtonByText(page, 'Remove Connection', inMain);
@@ -81,7 +81,7 @@ async function handleConnectButtonClick(page, username, inMain = true, handleSen
81
81
 
82
82
  if (connectButton && (await connectButton.isVisible())) {
83
83
  try {
84
- await connectButton.click();
84
+ await clickWithRetries(connectButton);
85
85
 
86
86
  if (handleSendWithoutNote) {
87
87
  await new Promise(resolve => setTimeout(resolve, 2000));
@@ -96,7 +96,7 @@ async function handleConnectButtonClick(page, username, inMain = true, handleSen
96
96
 
97
97
  if (sendWithoutNoteButton && (await sendWithoutNoteButton.isVisible())) {
98
98
  try {
99
- await sendWithoutNoteButton.click();
99
+ await clickWithRetries(sendWithoutNoteButton);
100
100
  await new Promise(resolve => setTimeout(resolve, 2000));
101
101
  return { status: 'success', message: `Connection request sent successfully to ${username}` };
102
102
  } catch (error) {
@@ -123,33 +123,56 @@ async function handleConnectButtonClick(page, username, inMain = true, handleSen
123
123
  }
124
124
 
125
125
  async function getButtonByText(page, text, inMain = false) {
126
- let buttons = [];
127
-
126
+ const candidates = Array.isArray(text) ? text : [text];
127
+ let elements = [];
128
128
  if (inMain) {
129
- const mainContent = page.locator('main');
130
- buttons = await mainContent.locator('button').all();
131
- const spans = await page.locator('div[role="button"] span').all();
132
- buttons = [...buttons, ...spans];
129
+ const main = page.locator('main');
130
+ elements = [
131
+ ...(await main.locator('button').all()),
132
+ ...(await main.locator('[role="button"]').all()),
133
+ ...(await main.locator('[aria-label]').all())
134
+ ];
133
135
  } else {
134
- buttons = await page.locator('button').all();
135
- const spans = await page.locator('div[role="button"] span').all();
136
- buttons = [...buttons, ...spans];
137
- }
138
-
139
- for (let i = 0; i < buttons.length; i++) {
140
- const button = buttons[i];
136
+ elements = [
137
+ ...(await page.locator('button').all()),
138
+ ...(await page.locator('[role="button"]').all()),
139
+ ...(await page.locator('[aria-label]').all())
140
+ ];
141
+ }
142
+ for (let i = 0; i < elements.length; i++) {
143
+ const el = elements[i];
141
144
  try {
142
- if (!(await button.isVisible())) {
143
- continue;
144
- }
145
- const buttonText = await button.textContent() || await button.innerText() || '';
146
- if (buttonText.trim() === text) {
147
- return button;
145
+ if (!(await el.isVisible())) continue;
146
+ const textContent = (await el.textContent()) || '';
147
+ const innerText = (await el.innerText()) || '';
148
+ const ariaLabel = (await el.getAttribute('aria-label')) || '';
149
+ const combined = `${textContent}\n${innerText}\n${ariaLabel}`.toLowerCase().replace(/\s+/g, ' ').trim();
150
+ for (const c of candidates) {
151
+ const needle = String(c).toLowerCase().trim();
152
+ if (!needle) continue;
153
+ if (combined === needle || combined.includes(needle)) {
154
+ await el.scrollIntoViewIfNeeded();
155
+ return el;
156
+ }
148
157
  }
149
- } catch (error) {
158
+ } catch (_) {
150
159
  continue;
151
160
  }
152
161
  }
153
-
154
162
  return null;
163
+ }
164
+
165
+ async function clickWithRetries(locator, retries = 3) {
166
+ for (let attempt = 0; attempt < retries; attempt++) {
167
+ try {
168
+ await locator.scrollIntoViewIfNeeded();
169
+ await locator.waitFor({ state: 'visible', timeout: 5000 });
170
+ await locator.click({ trial: false, timeout: 15000 });
171
+ return true;
172
+ } catch (_) {
173
+ await new Promise(r => setTimeout(r, 1000 * (attempt + 1)));
174
+ }
175
+ }
176
+ await locator.click();
177
+ return true;
155
178
  }