jackwener/OpenCLI · error · CommandExecutionError

Could not find the like control on ${post.code}

Error message

Could not find the like control on ${post.code}

What it means

After selecting the post, the library runs buildToggleLikeJs up to 5 times (sleeping 1s between attempts) to locate the post's like control in the page. This throw fires when all 5 attempts return click.found === false, meaning the like button/selector could not be found at all — usually because the page is not showing the post view the script expects.

Source

Thrown at clis/instagram/_shared/post-like.js:198

    }
    if (!Number.isInteger(index) || index < 1) {
        throw new ArgumentError('--index must be a positive integer', 'e.g. --index 2 for the second most recent post');
    }

    const snapshot = await readPostSnapshot(page, username, index, command);
    const post = pickPost(snapshot, username, index, command);
    const label = post.caption || `(post #${index})`;
    const settled = [{ status: shouldLike ? 'Already liked' : 'Already unliked', user: username, post: label }];
    if (post.liked === shouldLike) return settled;

    await page.goto(`https://www.instagram.com/p/${post.code}/`, { settleMs: 2000 });
    let click = null;
    for (let attempt = 0; attempt < 5 && !click?.found; attempt += 1) {
        if (attempt > 0) await page.sleep(1);
        click = unwrapEvaluateResult(await page.evaluate(buildToggleLikeJs(shouldLike)));
    }
    if (!click?.found) {
        throw new CommandExecutionError(
            `Could not find the like control on ${post.code}`,
            'Open the post in the browser and check whether Instagram is asking you to log in, or set the interface language to English.',
        );
    }
    if (click.already) {
        await confirmPersistedState(page, username, index, command, post, shouldLike);
        return settled;
    }

    for (let attempt = 0; attempt < 5; attempt += 1) {
        await page.sleep(1);
        if (unwrapEvaluateResult(await page.evaluate(buildReadLikeStateJs(shouldLike))) !== true) continue;
        // A rejected action reverts the icon shortly after the optimistic flip.
        await page.sleep(2);
        if (unwrapEvaluateResult(await page.evaluate(buildReadLikeStateJs(shouldLike))) === true) {
            await confirmPersistedState(page, username, index, command, post, shouldLike);
            return [{ status: shouldLike ? 'Liked' : 'Unliked', user: username, post: label }];
        }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Open the post in the automated browser and confirm it is not showing a login prompt; re-authenticate if needed
  2. Set the browser/interface language to English
  3. Retry later — temporary Instagram UI experiments can hide the control
  4. Update the library/buildToggleLikeJs selectors to match the current DOM

Example fix

null
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check that the post view is interactive, not a login wall
const bodyText = await page.evaluate(() => document.body.innerText);
if (/log in|sign up/i.test(bodyText.slice(0, 500))) throw new Error('login wall detected; re-authenticate first');

Type guard

function likeControlVisible(page) { return page.evaluate(() => !!document.querySelector('svg[aria-label="Like"], button[aria-label="Like"]')); }

Try / catch

try { await setInstagramPostLike(page, kwargs, true); } catch (e) { if (/Could not find the like control/.test(e.message)) { /* check login state & language, then retry once */ await ensureLoggedIn(page); return setInstagramPostLike(page, kwargs, true); } throw e; }

Prevention

When it happens

Trigger: Instagram showing a login wall or signup modal instead of the post; non-English interface language changing aria-labels/selectors the script matches on; the post detail view failing to open; DOM structure changes from Instagram updates.

Common situations: Expired or logged-out sessions hitting the login prompt; browsers set to a non-English locale; headless environment where the post modal never renders; recently changed Instagram DOM breaking selectors.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/ab737e9054933641. Report an issue: GitHub.