channel-worker 2.5.36 → 2.5.38
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
|
@@ -1550,7 +1550,33 @@ async function run({ page, payload, log }) {
|
|
|
1550
1550
|
// new one is the publish mutation response.
|
|
1551
1551
|
capturedReelIdsSnapshotLen = capturedReelIds.length;
|
|
1552
1552
|
try {
|
|
1553
|
-
|
|
1553
|
+
// Retry the publish click. The button is FOUND + enabled, yet
|
|
1554
|
+
// locator.click can still time out (transient overlay / React
|
|
1555
|
+
// re-render detaching the node → "locator.click: Timeout 5000ms").
|
|
1556
|
+
// Re-find + re-click up to 3×, and on the last try fall back to a raw
|
|
1557
|
+
// JS dispatch (bypasses Playwright's obscured/stable guards).
|
|
1558
|
+
let clickedPublish = false;
|
|
1559
|
+
for (let attempt = 0; attempt < 3 && !clickedPublish; attempt++) {
|
|
1560
|
+
const target = attempt === 0 ? pub : await findByVerbs(publishVerbs, { requireBottomHalf: true });
|
|
1561
|
+
if (!target) { await page.waitForTimeout(1500); continue; }
|
|
1562
|
+
try {
|
|
1563
|
+
await target.hit.click({ timeout: 15000 });
|
|
1564
|
+
clickedPublish = true;
|
|
1565
|
+
} catch (ce) {
|
|
1566
|
+
log('warn', `[fb-pw] publish click attempt ${attempt + 1}/3 failed: ${ce.message.slice(0, 90)}`);
|
|
1567
|
+
if (attempt === 2) {
|
|
1568
|
+
const js = await page.evaluate(() => {
|
|
1569
|
+
const el = document.querySelector("[__fbpw_target__='1']")
|
|
1570
|
+
|| [...document.querySelectorAll("[role='button'],button")].find(b => ((b.getAttribute('aria-label') || b.innerText || '').trim() === 'Đăng'));
|
|
1571
|
+
if (!el) return false;
|
|
1572
|
+
el.scrollIntoView({ block: 'center' }); el.click(); return true;
|
|
1573
|
+
}).catch(() => false);
|
|
1574
|
+
if (js) { clickedPublish = true; log('info', '[fb-pw] publish via JS-dispatch fallback'); }
|
|
1575
|
+
}
|
|
1576
|
+
if (!clickedPublish) await page.waitForTimeout(2000);
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
if (!clickedPublish) throw new Error(`publish button not clickable after 3 attempts`);
|
|
1554
1580
|
|
|
1555
1581
|
// FB shows a confirmation dialog ("Chia sẻ ai biết tin trên Facebook"
|
|
1556
1582
|
// / "Are you sure you want to share?") after the primary publish
|
|
@@ -221,22 +221,34 @@ async function run({ page, payload, log }) {
|
|
|
221
221
|
|
|
222
222
|
// 6) Click "Đăng".
|
|
223
223
|
log('info', '[fbphoto] clicking publish…');
|
|
224
|
-
// Tag the first
|
|
225
|
-
//
|
|
224
|
+
// Tag the first VISIBLE + ENABLED button matching `verbs`. Mirrors the
|
|
225
|
+
// proven upload_facebook.js findByVerbs: searches ALL [role='dialog']
|
|
226
|
+
// (not just the first — FB renders extra hidden dialogs), matches
|
|
227
|
+
// innerText||textContent (button label often lives in a nested span), then
|
|
228
|
+
// falls back to the whole document. Returns the matched verb, or null.
|
|
226
229
|
const tagCta = async (verbs) => page.evaluate((vbs) => {
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const r =
|
|
230
|
+
const tryScope = (roots, verb) => {
|
|
231
|
+
for (const root of roots) {
|
|
232
|
+
let best = null;
|
|
233
|
+
for (const el of root.querySelectorAll("button, [role='button']")) {
|
|
234
|
+
const t = (el.innerText || el.textContent || '').trim();
|
|
235
|
+
const a = (el.getAttribute('aria-label') || '').trim();
|
|
236
|
+
if (t !== verb && a !== verb) continue;
|
|
237
|
+
const r = el.getBoundingClientRect();
|
|
235
238
|
if (r.width < 8 || r.height < 8) continue;
|
|
236
|
-
|
|
237
|
-
|
|
239
|
+
const cs = getComputedStyle(el);
|
|
240
|
+
if (cs.visibility === 'hidden' || cs.display === 'none' || cs.opacity === '0') continue;
|
|
241
|
+
if (el.getAttribute('aria-disabled') === 'true' || el.disabled) continue;
|
|
242
|
+
best = el;
|
|
238
243
|
}
|
|
244
|
+
if (best) return best;
|
|
239
245
|
}
|
|
246
|
+
return null;
|
|
247
|
+
};
|
|
248
|
+
for (const v of vbs) {
|
|
249
|
+
const dlgs = Array.from(document.querySelectorAll("[role='dialog']"));
|
|
250
|
+
let el = tryScope(dlgs, v) || tryScope([document], v);
|
|
251
|
+
if (el) { el.setAttribute('__fbphoto_cta__', '1'); return v; }
|
|
240
252
|
}
|
|
241
253
|
return null;
|
|
242
254
|
}, verbs).catch(() => null);
|
|
@@ -260,6 +272,21 @@ async function run({ page, payload, log }) {
|
|
|
260
272
|
if (nextHit) { log('info', `[fbphoto] advance via "${nextHit}" (step ${step + 1})`); await clickTaggedCta(); await page.waitForTimeout(2800); stalls = 0; continue; }
|
|
261
273
|
// Neither publish nor Tiếp enabled — FB still ingesting the photo. Wait.
|
|
262
274
|
if (++stalls > 10) break; // ~30s of no CTA → give up
|
|
275
|
+
if (stalls === 1 || stalls === 6) {
|
|
276
|
+
// Diagnostic: what buttons ARE in the composer right now?
|
|
277
|
+
const btns = await page.evaluate(() => {
|
|
278
|
+
const out = [];
|
|
279
|
+
for (const dlg of document.querySelectorAll("[role='dialog']")) {
|
|
280
|
+
for (const el of dlg.querySelectorAll("button, [role='button']")) {
|
|
281
|
+
const t = (el.innerText || el.textContent || '').trim().slice(0, 30);
|
|
282
|
+
const r = el.getBoundingClientRect();
|
|
283
|
+
if (t && r.width > 20 && r.height > 8) out.push(`${t}${el.getAttribute('aria-disabled') === 'true' ? '(disabled)' : ''}`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return [...new Set(out)].slice(0, 20);
|
|
287
|
+
}).catch(() => []);
|
|
288
|
+
log('info', `[fbphoto] composer buttons: ${JSON.stringify(btns)}`);
|
|
289
|
+
}
|
|
263
290
|
log('info', `[fbphoto] no CTA yet at step ${step + 1} — waiting…`);
|
|
264
291
|
step--; // don't count a pure wait against the step budget
|
|
265
292
|
await page.waitForTimeout(3000);
|