Local social media automation dashboard for TikTok, Instagram, and YouTube.
Guard TikTok secondary publish confirmation
Katzca40424b16b478
diff --git a/src/tiktok-uploader.js b/src/tiktok-uploader.jsindex 395433e..3d88071 100644--- a/src/tiktok-uploader.js+++ b/src/tiktok-uploader.js@@ -240,7 +240,7 @@ async function getPublishCandidateInfo(candidate) {});}-async function clickFirstLikelyPublishLocator(page, locator) {+async function clickFirstLikelyPublishLocator(page, locator, publishTerms = uiLabels.terms("tiktokPublish")) {const total = await locator.count();if (total === 0) {return false;@@ -255,7 +255,7 @@ async function clickFirstLikelyPublishLocator(page, locator) {}const info = await getPublishCandidateInfo(candidate).catch(() => null);- const score = getPublishCandidateScore(info);+ const score = getPublishCandidateScore(info, publishTerms);if (score < 0) {continue;}@@ -954,16 +954,44 @@ function isLikelyPublishApiResponse(response) {}async function trySecondaryPublishConfirm(page) {- const confirmButtons = [- uiLabels.pattern("tiktokConfirm"),- ];+ const confirmTerms = uiLabels+ .terms("tiktokConfirm")+ .filter((term) => normalizeUiText(term) !== "post");+ const confirmPattern = new RegExp(confirmTerms.map(escapeRegExp).join("|"), "i");+ const scopedConfirmLocator = page+ .locator(+ [+ "[role='dialog']",+ "[aria-modal='true']",+ "[class*='modal' i]",+ "[class*='dialog' i]",+ "[class*='popover' i]",+ "[class*='drawer' i]",+ ].join(", ")+ )+ .locator("button, [role='button']")+ .filter({ hasText: confirmPattern });+ const scopedClicked = await clickFirstLikelyPublishLocator(+ page,+ scopedConfirmLocator,+ confirmTerms+ );+ if (scopedClicked) {+ await page.waitForTimeout(500);+ return true;+ }- for (const nameRegex of confirmButtons) {- const clicked = await clickFirstVisibleButton(page, nameRegex, 800);- if (clicked) {- await page.waitForTimeout(500);- return true;- }+ const confirmLocator = page.getByRole("button", {+ name: confirmPattern,+ });+ const clicked = await clickFirstLikelyPublishLocator(+ page,+ confirmLocator,+ confirmTerms+ );+ if (clicked) {+ await page.waitForTimeout(500);+ return true;}return false;diff --git a/test/tiktok-uploader.test.js b/test/tiktok-uploader.test.jsindex 1999e32..e11c08d 100644--- a/test/tiktok-uploader.test.js+++ b/test/tiktok-uploader.test.js@@ -90,3 +90,31 @@ test("TikTok publish candidate scores bottom Post button above sidebar Posts", (assert.equal(getPublishCandidateScore(sidebar), -1);assert.ok(getPublishCandidateScore(bottomButton) > 0);});++test("TikTok secondary confirm terms reject plain Post and sidebar Posts", () => {+ const sidebar = {+ disabled: false,+ inNavigation: false,+ rect: { left: 80, right: 190, top: 248, width: 110, height: 36 },+ role: "button",+ tagName: "button",+ text: "Posts",+ viewportHeight: 940,+ viewportWidth: 1154,+ };+ const bottomButton = {+ className: "TUXButton TUXButton--primary",+ disabled: false,+ inNavigation: false,+ rect: { left: 340, right: 540, top: 884, width: 200, height: 38 },+ role: "",+ tagName: "button",+ text: "Post",+ viewportHeight: 940,+ viewportWidth: 1154,+ };+ const secondaryTerms = ["publish", "confirm", "continue"];++ assert.equal(getPublishCandidateScore(sidebar, secondaryTerms), -1);+ assert.equal(getPublishCandidateScore(bottomButton, secondaryTerms), -1);+});