channel-worker 2.5.37 → 2.5.39

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": "channel-worker",
3
- "version": "2.5.37",
3
+ "version": "2.5.39",
4
4
  "description": "Channel Manager worker daemon — runs on remote machines to execute video pipeline jobs",
5
5
  "main": "lib/daemon.js",
6
6
  "bin": {
@@ -1550,7 +1550,49 @@ async function run({ page, payload, log }) {
1550
1550
  // new one is the publish mutation response.
1551
1551
  capturedReelIdsSnapshotLen = capturedReelIds.length;
1552
1552
  try {
1553
- await waitAndClick(pub.hit, { timeoutMs: 120_000, log, label: `Publish(${pub.verb})` });
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
+ let attemptedClick = false;
1560
+ // The publish button is gone → the composer closed, which on FB means
1561
+ // the post was ACCEPTED. Critical guard against the false-failure that
1562
+ // caused double-posts: FB registers the click and closes the composer,
1563
+ // but Playwright's click() promise still throws a timeout as the node
1564
+ // detaches. Treating that as a failure marked the idea unpublished →
1565
+ // the user re-posted → duplicate reel. So: if the button vanished
1566
+ // after we clicked, it went through.
1567
+ const publishBtnGone = async () => !(await findByVerbs(publishVerbs, { requireBottomHalf: true }));
1568
+ for (let attempt = 0; attempt < 3 && !clickedPublish; attempt++) {
1569
+ const target = attempt === 0 ? pub : await findByVerbs(publishVerbs, { requireBottomHalf: true });
1570
+ if (!target) {
1571
+ if (attemptedClick) { clickedPublish = true; log('info', '[fb-pw] publish button gone after click → post accepted'); break; }
1572
+ await page.waitForTimeout(1500); continue;
1573
+ }
1574
+ attemptedClick = true;
1575
+ try {
1576
+ await target.hit.click({ timeout: 15000 });
1577
+ clickedPublish = true;
1578
+ } catch (ce) {
1579
+ log('warn', `[fb-pw] publish click attempt ${attempt + 1}/3 threw: ${ce.message.slice(0, 90)}`);
1580
+ // Click may have registered before the node detached — if the
1581
+ // button is now gone, the post went through.
1582
+ if (await publishBtnGone()) { clickedPublish = true; log('info', '[fb-pw] click threw but publish button gone → post accepted'); break; }
1583
+ if (attempt === 2) {
1584
+ const js = await page.evaluate(() => {
1585
+ const el = document.querySelector("[__fbpw_target__='1']")
1586
+ || [...document.querySelectorAll("[role='button'],button")].find(b => ((b.getAttribute('aria-label') || b.innerText || '').trim() === 'Đăng'));
1587
+ if (!el) return false;
1588
+ el.scrollIntoView({ block: 'center' }); el.click(); return true;
1589
+ }).catch(() => false);
1590
+ if (js) { clickedPublish = true; log('info', '[fb-pw] publish via JS-dispatch fallback'); }
1591
+ }
1592
+ if (!clickedPublish) await page.waitForTimeout(2000);
1593
+ }
1594
+ }
1595
+ if (!clickedPublish) throw new Error(`publish button not clickable after 3 attempts`);
1554
1596
 
1555
1597
  // FB shows a confirmation dialog ("Chia sẻ ai biết tin trên Facebook"
1556
1598
  // / "Are you sure you want to share?") after the primary publish