channel-worker 2.5.133 → 2.5.134

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.133",
3
+ "version": "2.5.134",
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": {
@@ -722,6 +722,407 @@ async function sampleCustomThumb(page, { samples = 3, gapMs = 1500 } = {}) {
722
722
  return { verdict: thumbVerdict(out), samples: out };
723
723
  }
724
724
 
725
+ // ─── Composer MỚI của Facebook (bắt 22-23/09/2026) ──────────────────────────
726
+ // Ba page (LACCA, Nhà Nhỏ Có Võ, Gà Vườn Mỗi Ngày) hỏng 11/11 lượt với
727
+ // "Custom thumbnail required but not applied". Chuỗi log lượt nào cũng như
728
+ // nhau: nút "Thước phim" trên tường không mở hộp thoại → nhánh dự phòng bấm
729
+ // link "Tạo thước phim" → link đó giờ đưa sang giao diện mới:
730
+ // /post/create form MỘT trang (9 lượt)
731
+ // /reels/create/?surface=ADDL_PROFILE_PLUS wizard "Chỉnh sửa › Cài đặt" (2 lượt)
732
+ // Khối ảnh bìa cũ chỉ chạy khi URL là facebook.com/ trần, nên cả khối bị bỏ
733
+ // qua (log mấy lượt đó không có một dòng thumb nào) và cổng trước Đăng chặn.
734
+ //
735
+ // Giao diện mới không có nút "Chỉnh sửa hình thu nhỏ". Mục "Hình thu nhỏ" là
736
+ // MỘT HÀNG Ô: ô đầu viền nét đứt ghi "Chọn hình thu nhỏ", tiếp theo là các
737
+ // khung FB tự cắt từ video, khung đang chọn viền xanh. KHÔNG được nới regex
738
+ // cho khối cũ: trên /post/create ô video có nút "Chỉnh sửa" riêng, bộ dò
739
+ // "narrow-pill" của khối cũ sẽ bấm nhầm vào trình sửa video.
740
+ const NEW_COMPOSER_URL_RE = /^https?:\/\/(www\.)?facebook\.com\/(post\/create|reels\/create)(\/|\?|#|$)/i;
741
+ function isNewComposerUrl(url) {
742
+ return NEW_COMPOSER_URL_RE.test(String(url || ''));
743
+ }
744
+ // Chữ trên ô "tải ảnh bìa của mình lên" — khớp NGUYÊN chuỗi (sau khi gộp
745
+ // khoảng trắng) để không dính caption hay nhãn mục "Hình thu nhỏ".
746
+ const THUMB_PICKER_TEXT_RE = /^(?:Chọn hình thu nhỏ|Chọn ảnh thu nhỏ|Thêm hình thu nhỏ|Tải hình thu nhỏ lên|(?:Choose|Select|Add|Upload) (?:a )?(?:custom )?thumbnail)$/i;
747
+
748
+ // Đọc hàng ô ảnh bìa của composer mới. Trả về ảnh chụp trạng thái để so
749
+ // trước/sau khi dán (xem newComposerThumbVerdict), và gắn cờ DOM cho:
750
+ // __fbpw_thumb_pick__ — chỗ bấm của ô "Chọn hình thu nhỏ"
751
+ // __fbpw_thumb_row__ — chính hàng ô (để tìm lại khi ô chọn-ảnh đã biến mất)
752
+ // __fbpw_thumb_input__ — input file CHỈ nhận ảnh nằm trong mục ảnh bìa
753
+ // __fbpw_thumb_tile__ — ô thứ `tagIndex` (dùng khi phải bấm chọn lại)
754
+ // Không bao giờ ném: đọc hỏng trả null, như isCustomThumbApplied.
755
+ async function readNewComposerThumbRow(page, { diag = false, tagIndex = -1 } = {}) {
756
+ return page.evaluate(({ pickSrc, diag, tagIndex }) => {
757
+ const PICK = new RegExp(pickSrc, 'i');
758
+ const norm = (s) => String(s || '').replace(/\s+/g, ' ').trim();
759
+ const vis = (el) => {
760
+ const r = el.getBoundingClientRect();
761
+ if (r.width < 8 || r.height < 8) return false;
762
+ const cs = getComputedStyle(el);
763
+ return cs.visibility !== 'hidden' && cs.display !== 'none' && cs.opacity !== '0';
764
+ };
765
+ for (const a of ['__fbpw_thumb_pick__', '__fbpw_thumb_input__', '__fbpw_thumb_tile__']) {
766
+ document.querySelectorAll(`[${a}]`).forEach((el) => el.removeAttribute(a));
767
+ }
768
+ const isPick = (el) => PICK.test(norm(el.getAttribute && el.getAttribute('aria-label')))
769
+ || PICK.test(norm(el.innerText));
770
+ // Ảnh của một ô: <img>, <image> trong SVG, hoặc background-image. Bỏ qua
771
+ // icon nhỏ (ô chọn-ảnh có icon ~20px).
772
+ const mediaOf = (el) => {
773
+ for (const m of el.querySelectorAll("img, image, [style*='background-image']")) {
774
+ const r = m.getBoundingClientRect();
775
+ if (r.width < 40 || r.height < 40) continue;
776
+ const tag = m.tagName.toLowerCase();
777
+ let src = '';
778
+ if (tag === 'img') src = m.currentSrc || m.src || '';
779
+ else if (tag === 'image') src = m.getAttribute('href') || m.getAttribute('xlink:href') || '';
780
+ else src = ((m.style.backgroundImage || '').match(/url\(["']?(.*?)["']?\)/) || [])[1] || '';
781
+ if (src) return src.slice(0, 500);
782
+ }
783
+ return '';
784
+ };
785
+ const tileLike = (el) => vis(el) && (!!mediaOf(el) || isPick(el));
786
+ // Ô đang chọn: viền/bóng xanh của FB (#0866FF, #1877F2) hoặc aria-*.
787
+ const blueish = (c) => {
788
+ const m = String(c || '').match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?/);
789
+ if (!m) return false;
790
+ const [r, g, b] = [+m[1], +m[2], +m[3]];
791
+ const a = m[4] === undefined ? 1 : +m[4];
792
+ return a > 0.5 && b >= 180 && r <= 100 && g >= 60 && g <= 180;
793
+ };
794
+ const selOf = (tile) => {
795
+ for (const e of [tile, ...tile.querySelectorAll('*')].slice(0, 40)) {
796
+ for (const a of ['aria-checked', 'aria-selected', 'aria-pressed', 'aria-current']) {
797
+ if (e.getAttribute(a) === 'true') return true;
798
+ }
799
+ const cs = getComputedStyle(e);
800
+ if (parseFloat(cs.borderTopWidth) >= 2 && cs.borderTopStyle === 'solid' && blueish(cs.borderTopColor)) return true;
801
+ if (cs.boxShadow && cs.boxShadow !== 'none' && blueish(cs.boxShadow)) return true;
802
+ }
803
+ return false;
804
+ };
805
+ // Hàng ô = tổ tiên gần nhất có >= 2 con trông như ô ảnh.
806
+ const rowFrom = (el) => {
807
+ let node = el;
808
+ for (let d = 0; d < 10 && node && node.parentElement; d++) {
809
+ const p = node.parentElement;
810
+ if ([...p.children].filter(tileLike).length >= 2) return p;
811
+ node = p;
812
+ }
813
+ return null;
814
+ };
815
+
816
+ const roots = [...document.querySelectorAll("[role='dialog']")].filter((d) => vis(d)
817
+ && /thước phim|reel/i.test(`${d.getAttribute('aria-label') || ''}\n${(d.innerText || '').slice(0, 600)}`));
818
+ const main = document.querySelector("[role='main'], main");
819
+ if (main && vis(main) && /^\/(post|reels)\/create/i.test(location.pathname)) roots.push(main);
820
+
821
+ // Đi theo NÚT CHỮ thay vì đọc innerText của mọi phần tử: composer thật có
822
+ // vài nghìn phần tử, innerText mỗi cái bắt trình duyệt dàn trang lại.
823
+ // Leo tối đa 4 tầng vì chữ có thể bị tách ("Chọn hình" / "thu nhỏ").
824
+ const textHits = (root, keyRe, fullRe) => {
825
+ const out = [];
826
+ const tw = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
827
+ for (let n = tw.nextNode(); n; n = tw.nextNode()) {
828
+ if (!keyRe.test(n.data)) continue;
829
+ for (let el = n.parentElement, d = 0; el && d < 4; el = el.parentElement, d++) {
830
+ if (fullRe.test(norm(el.innerText)) && vis(el)) { out.push(el); break; }
831
+ if (el === root) break;
832
+ }
833
+ }
834
+ return out;
835
+ };
836
+ let pickLeaf = null;
837
+ for (const root of roots) {
838
+ const hits = [...root.querySelectorAll('[aria-label]')].filter((el) => PICK.test(norm(el.getAttribute('aria-label'))) && vis(el))
839
+ .concat(textHits(root, /hình|ảnh|thumbnail/i, PICK));
840
+ if (hits.length) { pickLeaf = hits[0]; break; }
841
+ }
842
+ let row = null;
843
+ let via = '';
844
+ if (pickLeaf) { row = rowFrom(pickLeaf); via = 'pick'; }
845
+ if (!row) {
846
+ const tagged = document.querySelector('[__fbpw_thumb_row__]');
847
+ if (tagged && tagged.isConnected && vis(tagged)) { row = tagged; via = 'tagged'; }
848
+ }
849
+ if (!row) {
850
+ // Ô chọn-ảnh đã biến mất (bị ảnh vừa dán thay chỗ) và FB dựng lại hàng:
851
+ // lần theo nhãn mục "Hình thu nhỏ".
852
+ for (const root of roots) {
853
+ // Leo từ nút chữ lên nên được phần tử SÂU nhất. Quan trọng: khi ô
854
+ // chọn-ảnh đã thành ảnh, cả khung mục (nhãn + hàng ô) cũng chỉ còn
855
+ // đúng chữ "Hình thu nhỏ" — ảnh không có chữ — nên dò từ trên xuống
856
+ // sẽ vớ khung mục chứ không phải nhãn (trang giả lập bắt được ca này).
857
+ const head = textHits(root, /^\s*(Hình thu nhỏ|Thumbnail)\s*$/i, /^(Hình thu nhỏ|Thumbnail)$/i)[0];
858
+ if (!head) continue;
859
+ let node = head;
860
+ for (let d = 0; d < 4 && node && !row; d++) {
861
+ for (let sib = node.nextElementSibling; sib && !row; sib = sib.nextElementSibling) {
862
+ const all = [sib, ...sib.querySelectorAll('*')];
863
+ row = all.find((el) => [...el.children].filter(tileLike).length >= 2) || null;
864
+ }
865
+ node = node.parentElement;
866
+ }
867
+ if (row) { via = 'heading'; break; }
868
+ }
869
+ }
870
+ const customMarker = [...document.querySelectorAll('[aria-label]')].some((el) =>
871
+ /Gỡ hình thu nhỏ tùy chỉnh|Remove( your)? custom thumbnail/i.test(el.getAttribute('aria-label') || '') && vis(el));
872
+ if (!row) {
873
+ const miss = { found: false, pickerPresent: !!pickLeaf, roots: roots.length, customMarker };
874
+ if (diag) {
875
+ // Không thấy hàng ô: kê các nút của composer, như thumb-diag của khối cũ,
876
+ // để biết ảnh bìa nằm ở đâu trên biến thể này.
877
+ miss.inventory = [];
878
+ for (const root of roots) {
879
+ for (const el of root.querySelectorAll("[role='button'], button, [aria-label], input[type='file']")) {
880
+ if (miss.inventory.length >= 45) break;
881
+ const r = el.getBoundingClientRect();
882
+ const t = norm(el.innerText).slice(0, 28);
883
+ const al = (el.getAttribute('aria-label') || '').slice(0, 40);
884
+ const acc = el.tagName === 'INPUT' ? ` accept=${el.getAttribute('accept') || ''}` : '';
885
+ if ((t || al || acc) && (acc || (r.width >= 10 && r.height >= 10))) miss.inventory.push(`<${el.tagName.toLowerCase()}> t="${t}" al="${al}"${acc} ${Math.round(r.width)}x${Math.round(r.height)}`);
886
+ }
887
+ }
888
+ }
889
+ return miss;
890
+ }
891
+
892
+ document.querySelectorAll('[__fbpw_thumb_row__]').forEach((el) => { if (el !== row) el.removeAttribute('__fbpw_thumb_row__'); });
893
+ row.setAttribute('__fbpw_thumb_row__', '1');
894
+ const tiles = [...row.children].filter(tileLike);
895
+ const out = tiles.map((t) => ({ img: mediaOf(t), placeholder: isPick(t), selected: selOf(t) }));
896
+ const flagged = out.map((t, i) => (t.selected ? i : -1)).filter((i) => i >= 0);
897
+
898
+ let pickerPresent = false;
899
+ const pickTile = tiles.find((t) => isPick(t));
900
+ if (pickTile) {
901
+ pickerPresent = true;
902
+ // Bấm vào phần tử bấm-được sâu nhất bên trong ô, không có thì bấm cả ô.
903
+ let target = null;
904
+ const leaf = [...pickTile.querySelectorAll('*')].filter((el) => vis(el) && isPick(el)).pop() || pickTile;
905
+ for (let n = leaf; n && n !== row; n = n.parentElement) {
906
+ if (n.matches("[role='button'], button, label, a, [tabindex]")) { target = n; break; }
907
+ }
908
+ (target || pickTile).setAttribute('__fbpw_thumb_pick__', '1');
909
+ }
910
+ let input = null;
911
+ for (let scope = row, d = 0; scope && d < 3 && !input; scope = scope.parentElement, d++) {
912
+ for (const el of scope.querySelectorAll("input[type='file']")) {
913
+ const accept = (el.getAttribute('accept') || '').toLowerCase();
914
+ if (!/image/.test(accept) || /video/.test(accept)) continue; // input của "Thêm file khác" nhận cả video
915
+ el.setAttribute('__fbpw_thumb_input__', '1');
916
+ input = { accept: accept.slice(0, 60) };
917
+ break;
918
+ }
919
+ }
920
+ if (tagIndex >= 0 && tiles[tagIndex]) tiles[tagIndex].setAttribute('__fbpw_thumb_tile__', '1');
921
+
922
+ const res = {
923
+ found: true,
924
+ via,
925
+ pickerPresent,
926
+ tiles: out,
927
+ selectedIndex: flagged.length === 1 ? flagged[0] : null,
928
+ customMarker,
929
+ input,
930
+ };
931
+ if (diag) {
932
+ // Khung xương mục ảnh bìa, để lần sau FB đổi DOM còn có cái mà soi.
933
+ const sec = row.parentElement || row;
934
+ res.skeleton = [sec, ...sec.querySelectorAll('*')].filter((el) => el.tagName !== 'path').slice(0, 60).map((el) => {
935
+ const r = el.getBoundingClientRect();
936
+ const role = el.getAttribute('role');
937
+ const al = el.getAttribute('aria-label');
938
+ const own = el.children.length ? '' : norm(el.innerText).slice(0, 20);
939
+ const acc = el.tagName === 'INPUT' ? ` accept=${el.getAttribute('accept') || ''}` : '';
940
+ return `<${el.tagName.toLowerCase()}${role ? ` role=${role}` : ''}${al ? ` al="${al.slice(0, 30)}"` : ''}${own ? ` t="${own}"` : ''}${acc}> ${Math.round(r.width)}x${Math.round(r.height)}`;
941
+ });
942
+ }
943
+ return res;
944
+ }, { pickSrc: THUMB_PICKER_TEXT_RE.source, diag, tagIndex }).catch(() => null);
945
+ }
946
+
947
+ // Ảnh bìa tự chọn đã VÀO composer mới chưa? So hàng ô trước và sau khi dán
948
+ // (thuần, test được). Chỉ nhận hai dấu hiệu gắn với CHÍNH ô chọn-ảnh, không
949
+ // nhận "có ảnh lạ xuất hiện đâu đó": FB có thể dựng lại các khung tự động với
950
+ // URL mới, coi đó là ảnh của mình thì bài lên với ảnh bìa tự động — đúng thứ
951
+ // cổng trước Đăng sinh ra để chặn.
952
+ // A. ô chọn-ảnh bị thay bằng một ảnh mới (cùng vị trí, hết chữ "Chọn…")
953
+ // B. hàng thêm đúng MỘT ô, ô mới có ảnh chưa từng thấy và nằm sát ô chọn-ảnh
954
+ // Rồi mới xét ô đang chọn: đọc được mà không phải ô của mình → 'not-selected'.
955
+ function newComposerThumbVerdict(before, after) {
956
+ if (after && after.customMarker) return { verdict: 'applied', why: 'nút "Gỡ hình thu nhỏ tùy chỉnh" đang hiện' };
957
+ if (!before || !before.found || !after || !after.found) {
958
+ return { verdict: 'unknown', why: 'không đọc được hàng ô ảnh bìa' };
959
+ }
960
+ const bTiles = before.tiles || [];
961
+ const aTiles = after.tiles || [];
962
+ const seen = new Set(bTiles.map((t) => t.img).filter(Boolean));
963
+ const p = bTiles.findIndex((t) => t.placeholder);
964
+ let custom = -1;
965
+ let how = '';
966
+ if (p >= 0 && aTiles[p] && aTiles[p].img && !aTiles[p].placeholder && !seen.has(aTiles[p].img)) {
967
+ custom = p;
968
+ how = 'ô "Chọn hình thu nhỏ" đã thành ảnh mới';
969
+ }
970
+ if (custom < 0 && aTiles.length === bTiles.length + 1) {
971
+ const anchor = Math.max(p, 0);
972
+ const i = aTiles.findIndex((t, k) => t.img && !seen.has(t.img) && Math.abs(k - anchor) <= 1);
973
+ if (i >= 0) { custom = i; how = `thêm ô ảnh mới ở vị trí ${i}`; }
974
+ }
975
+ if (custom < 0) return { verdict: 'absent', why: 'hàng ô không có ảnh nào mới ở chỗ ô chọn-ảnh' };
976
+ const sel = after.selectedIndex;
977
+ if (sel === null || sel === undefined) {
978
+ return { verdict: 'applied', customIndex: custom, why: `${how}; không đọc được ô đang chọn` };
979
+ }
980
+ if (sel === custom) return { verdict: 'applied', customIndex: custom, why: `${how}, đang được chọn` };
981
+ return { verdict: 'not-selected', customIndex: custom, why: `${how} nhưng ô đang chọn là ${sel}` };
982
+ }
983
+
984
+ // Tóm tắt một hàng ô cho log: "5 ô [chọn-ảnh, *khung, khung…] chọn=1 input=image/*".
985
+ function describeThumbRow(snap) {
986
+ if (!snap) return 'không đọc được';
987
+ if (!snap.found) return `không thấy hàng ô (composer=${snap.roots || 0}, ô chọn-ảnh=${snap.pickerPresent ? 'có' : 'không'})`;
988
+ const cells = (snap.tiles || []).map((t) => `${t.selected ? '*' : ''}${t.placeholder ? 'chọn-ảnh' : (t.img ? (/^(blob|data):/.test(t.img) ? 'ảnh-local' : 'khung') : '?')}`);
989
+ return `${cells.length} ô [${cells.join(', ')}] chọn=${snap.selectedIndex ?? '?'} input=${snap.input ? snap.input.accept || '?' : 'không'} via=${snap.via}`;
990
+ }
991
+
992
+ // Hộp phụ FB có thể bật lên sau khi nhận ảnh (cắt ảnh / xác nhận). Chưa thấy
993
+ // tận mắt — chỉ bấm nút xác nhận của một dialog KHÁC composer mà trong chữ
994
+ // có nhắc ảnh bìa, để không bao giờ trúng nút "Lưu" (= lưu nháp) của composer.
995
+ async function confirmNewComposerThumbDialog(page, log) {
996
+ const hit = await page.evaluate((compSrc) => {
997
+ const COMP = new RegExp(compSrc, 'i');
998
+ for (const dlg of document.querySelectorAll("[role='dialog']")) {
999
+ const r = dlg.getBoundingClientRect();
1000
+ if (r.width < 8 || r.height < 8) continue;
1001
+ const head = `${dlg.getAttribute('aria-label') || ''} | ${(dlg.innerText || '').slice(0, 300)}`;
1002
+ if (COMP.test(head)) continue;
1003
+ if (!/hình thu nhỏ|ảnh thu nhỏ|thumbnail|cắt ảnh|crop/i.test(head)) continue;
1004
+ for (const b of dlg.querySelectorAll("button, [role='button']")) {
1005
+ const t = (b.innerText || '').trim();
1006
+ const br = b.getBoundingClientRect();
1007
+ if (br.width < 8 || br.height < 8 || b.getAttribute('aria-disabled') === 'true') continue;
1008
+ if (!/^(Lưu|Xong|Áp dụng|Save|Done|Apply)$/i.test(t)) continue;
1009
+ b.setAttribute('__fbpw_thumb_confirm__', '1');
1010
+ return { verb: t, head: head.slice(0, 60).replace(/\s+/g, ' ') };
1011
+ }
1012
+ }
1013
+ return null;
1014
+ }, COMPOSER_SIGNATURE_RE.source).catch(() => null);
1015
+ if (!hit) return false;
1016
+ log('info', `[fb-pw] composer mới — hộp phụ ảnh bìa "${hit.head}" → bấm "${hit.verb}"`);
1017
+ await page.locator("[__fbpw_thumb_confirm__='1']").click({ timeout: 3000 }).catch(() => {});
1018
+ await page.evaluate(() => document.querySelectorAll('[__fbpw_thumb_confirm__]').forEach((el) => el.removeAttribute('__fbpw_thumb_confirm__'))).catch(() => {});
1019
+ return true;
1020
+ }
1021
+
1022
+ // Dán ảnh bìa vào composer mới. Trả { applied, reason }. Không ném: thất bại
1023
+ // thì cờ customThumbDone không bật và cổng trước Đăng chặn như cũ.
1024
+ async function applyNewComposerThumb(page, thumbPath, log, { waitPickerMs = 20_000, verifyMs = 30_000 } = {}) {
1025
+ const t0 = Date.now();
1026
+ const ready = (s) => !!(s && s.found && s.pickerPresent);
1027
+ let snap = await readNewComposerThumbRow(page);
1028
+ // Hàng ảnh bìa chỉ hiện sau khi FB cắt xong khung từ video.
1029
+ while (!ready(snap) && Date.now() - t0 < waitPickerMs) {
1030
+ await pause(page, 2500);
1031
+ snap = await readNewComposerThumbRow(page);
1032
+ }
1033
+ if (!ready(snap)) {
1034
+ const d = await readNewComposerThumbRow(page, { diag: true });
1035
+ log('info', `[fb-pw] composer mới — chưa thấy ô "Chọn hình thu nhỏ" sau ${Math.round((Date.now() - t0) / 1000)}s: ${describeThumbRow(d)}${d && d.skeleton ? ` skeleton=${JSON.stringify(d.skeleton)}` : ''}${d && d.inventory ? ` nút=${JSON.stringify(d.inventory)}` : ''}`);
1036
+ return { applied: false, reason: 'no-picker' };
1037
+ }
1038
+ // Lấy mốc "trước" khi số ô đã đứng yên: FB mọc thêm khung dần dần, một khung
1039
+ // mọc muộn không được bị tưởng là ảnh bìa của mình.
1040
+ for (let i = 0; i < 3; i++) {
1041
+ await pause(page, 1500);
1042
+ const again = await readNewComposerThumbRow(page);
1043
+ if (!ready(again)) continue;
1044
+ const settled = again.tiles.length === snap.tiles.length;
1045
+ snap = again;
1046
+ if (settled) break;
1047
+ }
1048
+ const before = snap;
1049
+ log('info', `[fb-pw] composer mới — hàng ảnh bìa trước khi dán: ${describeThumbRow(before)}`);
1050
+
1051
+ let via = '';
1052
+ try {
1053
+ const [chooser] = await Promise.all([
1054
+ page.waitForEvent('filechooser', { timeout: 8000 }),
1055
+ page.locator("[__fbpw_thumb_pick__='1']").first().click({ timeout: 5000 }),
1056
+ ]);
1057
+ await chooser.setFiles(thumbPath);
1058
+ via = 'hộp chọn file';
1059
+ } catch (e) {
1060
+ log('info', `[fb-pw] composer mới — bấm ô "Chọn hình thu nhỏ" không mở hộp chọn file: ${String(e && e.message || e).slice(0, 80)}`);
1061
+ }
1062
+ if (!via) {
1063
+ await readNewComposerThumbRow(page); // cú bấm có thể làm FB dựng lại DOM → gắn cờ lại
1064
+ const input = page.locator("[__fbpw_thumb_input__='1']").first();
1065
+ if (await input.count().catch(() => 0)) {
1066
+ try {
1067
+ await input.setInputFiles(thumbPath);
1068
+ via = 'input file chỉ nhận ảnh';
1069
+ } catch (e) {
1070
+ log('info', `[fb-pw] composer mới — input ảnh bìa từ chối file: ${String(e && e.message || e).slice(0, 80)}`);
1071
+ }
1072
+ }
1073
+ }
1074
+ if (!via) {
1075
+ const d = await readNewComposerThumbRow(page, { diag: true });
1076
+ log('warn', `[fb-pw] composer mới — KHÔNG đưa được file ảnh bìa vào: ${describeThumbRow(d)}${d && d.skeleton ? ` skeleton=${JSON.stringify(d.skeleton)}` : ''}`);
1077
+ return { applied: false, reason: 'no-upload' };
1078
+ }
1079
+ log('info', `[fb-pw] composer mới — đã đưa file ảnh bìa vào qua ${via}, chờ FB nhận…`);
1080
+
1081
+ let v = { verdict: 'unknown', why: 'chưa đo' };
1082
+ let after = null;
1083
+ // Đòi HAI nhịp liền cùng thấy ảnh đã vào: ô có thể hiện ảnh xem trước ngay
1084
+ // khi nhận file, lúc FB còn đang tải lên và có thể trả lỗi rồi gỡ ra.
1085
+ let appliedStreak = 0;
1086
+ let notSelectedPolls = 0;
1087
+ let selectTried = false;
1088
+ let confirmTried = false;
1089
+ const deadline = Date.now() + verifyMs;
1090
+ while (Date.now() < deadline) {
1091
+ await pause(page, 2500);
1092
+ after = await readNewComposerThumbRow(page);
1093
+ v = newComposerThumbVerdict(before, after);
1094
+ if (v.verdict === 'applied') {
1095
+ if (++appliedStreak >= 2) break;
1096
+ continue;
1097
+ }
1098
+ appliedStreak = 0;
1099
+ if (v.verdict === 'absent' && !confirmTried) {
1100
+ confirmTried = await confirmNewComposerThumbDialog(page, log);
1101
+ continue;
1102
+ }
1103
+ // FB có thể cần một nhịp mới chuyển viền xanh sang ảnh vừa dán; hai nhịp
1104
+ // liền vẫn lệch thì bấm chọn ô đó MỘT lần. Canh sẵn hộp chọn file: nếu cú
1105
+ // bấm lại mở hộp chọn (ô vẫn là nút tải lên), dán lại đúng file đó chứ
1106
+ // không để hộp thoại hệ điều hành treo trên trình duyệt.
1107
+ if (v.verdict === 'not-selected' && ++notSelectedPolls >= 2 && !selectTried) {
1108
+ selectTried = true;
1109
+ await readNewComposerThumbRow(page, { tagIndex: v.customIndex });
1110
+ const chooserP = page.waitForEvent('filechooser', { timeout: 3000 }).catch(() => null);
1111
+ await page.locator("[__fbpw_thumb_tile__='1']").first().click({ timeout: 3000 }).catch(() => {});
1112
+ const ch = await chooserP;
1113
+ if (ch) await ch.setFiles(thumbPath).catch(() => {});
1114
+ log('info', `[fb-pw] composer mới — ${v.why} → bấm chọn ô ${v.customIndex}${ch ? ' (mở lại hộp chọn file, dán lại)' : ''}`);
1115
+ }
1116
+ }
1117
+ if (v.verdict === 'applied' && appliedStreak >= 2) {
1118
+ log('info', `[fb-pw] composer mới — ảnh bìa đã vào: ${v.why} — ${describeThumbRow(after)}`);
1119
+ return { applied: true, reason: v.why };
1120
+ }
1121
+ const d = await readNewComposerThumbRow(page, { diag: true });
1122
+ log('warn', `[fb-pw] composer mới — dán ảnh bìa KHÔNG xác nhận được (${v.verdict}: ${v.why}) — trước: ${describeThumbRow(before)} — sau: ${describeThumbRow(d)}${d && d.skeleton ? ` skeleton=${JSON.stringify(d.skeleton)}` : ''}`);
1123
+ return { applied: false, reason: v.verdict };
1124
+ }
1125
+
725
1126
  // Composer đang ở trạng thái gì? Đọc từ CHỮ trong hộp thoại — ba chữ ký nhìn
726
1127
  // được từ ảnh dump 10-11/09 (5 ca "KHÔNG commit" + 2 ca no-advance-3):
727
1128
  // rightsCheck : dòng đỏ "Không hoàn tất được quy trình kiểm tra bản quyền."
@@ -1224,7 +1625,7 @@ async function runOnce({ page, payload, log }) {
1224
1625
  } = payload || {};
1225
1626
  if (!video_url) throw new Error('No video_url provided');
1226
1627
 
1227
- log('info', '[fb-pw] selectors version=2026.09.14-deep-baseline');
1628
+ log('info', '[fb-pw] selectors version=2026.09.23-new-composer-thumb');
1228
1629
 
1229
1630
  page.on('dialog', (d) => { d.accept().catch(() => {}); });
1230
1631
 
@@ -2089,6 +2490,15 @@ async function runOnce({ page, payload, log }) {
2089
2490
  await pause(page, 3000);
2090
2491
  await fillMetadata();
2091
2492
 
2493
+ // COMPOSER MỚI (/post/create, /reels/create…) — ảnh bìa là ô "Chọn hình
2494
+ // thu nhỏ" trong hàng khung, không có nút "Chỉnh sửa hình thu nhỏ". Xem
2495
+ // applyNewComposerThumb. Chạy ở mọi bước cho tới khi dán được: form một
2496
+ // trang chỉ có một bước, wizard có thể để hàng ô ở bước sau.
2497
+ if (!customThumbDone && thumbPath && isNewComposerUrl(page.url())) {
2498
+ const nt = await applyNewComposerThumb(page, thumbPath, log);
2499
+ if (nt.applied) customThumbDone = true;
2500
+ }
2501
+
2092
2502
  // PAGE-WALL thumb flow (form 2 has a "Chỉnh sửa" overlay button on the
2093
2503
  // video preview → opens "Chỉnh sửa hình thu nhỏ" modal → "Tải lên" →
2094
2504
  // file picker → "Lưu"). Per user screenshots, this is the only way to
@@ -3681,6 +4091,15 @@ module.exports.__testables = {
3681
4091
  // Phán quyết "ảnh bìa đã áp chưa" từ nhiều mẫu đo — một mẫu đo hỏng không
3682
4092
  // được biến thành "chưa áp" rồi kéo theo hành động PHÁ (Hủy = gỡ ảnh bìa).
3683
4093
  thumbVerdict,
4094
+ // Composer mới (/post/create, /reels/create…) — ảnh bìa là ô "Chọn hình thu
4095
+ // nhỏ" trong hàng khung. Phán quyết thuần + luồng dán để chạy thử trên trang
4096
+ // giả lập.
4097
+ isNewComposerUrl,
4098
+ THUMB_PICKER_TEXT_RE,
4099
+ newComposerThumbVerdict,
4100
+ describeThumbRow,
4101
+ readNewComposerThumbRow,
4102
+ applyNewComposerThumb,
3684
4103
  // Dùng chung cho comment_facebook: script nào trượt giữa chừng cũng cần chụp
3685
4104
  // lại màn hình, viết bản thứ hai là sớm muộn hai bên lệch nhau.
3686
4105
  dumpFailure,