jackwener/OpenCLI · error · AuthRequiredError

Please log in to the WeChat Official Account platform and re

Error message

Please log in to the WeChat Official Account platform and retry.

What it means

navigateToEditor opens mp.weixin.qq.com and looks for a token= digits parameter in the URL, which only appears for an authenticated session. If no token is found it throws AuthRequiredError telling you to log in to the WeChat Official Account platform and retry.

Source

Thrown at clis/weixin/create-draft.js:59

        throw new ArgumentError(`weixin create-draft cover-image does not exist: ${absPath}`);
    }
    if (!stat.isFile()) {
        throw new ArgumentError(`weixin create-draft cover-image is not a file: ${absPath}`);
    }
    const extension = path.extname(absPath).toLowerCase();
    const mimeType = IMAGE_MIME_TYPES.get(extension);
    if (!mimeType) {
        throw new ArgumentError('weixin create-draft cover-image must be JPEG, PNG, GIF, or WebP');
    }
    return { absPath, fileName: path.basename(absPath), mimeType };
}

async function navigateToEditor(page) {
    await page.goto(WEIXIN_HOME);
    await page.wait(3);
    const token = await evaluate(page, `(window.location.href.match(/token=(\\d+)/)||[])[1]`);
    if (!token) {
        throw new AuthRequiredError(WEIXIN_DOMAIN, 'Please log in to the WeChat Official Account platform and retry.');
    }
    await page.goto(`https://mp.weixin.qq.com/cgi-bin/appmsg?t=media/appmsg_edit_v2&action=edit&isNew=1&type=77&token=${token}&lang=zh_CN`);
    await page.wait(4);
    const hasTitle = await evaluate(page, '!!document.querySelector("textarea#title")');
    if (hasTitle !== true) {
        throw new CommandExecutionError('WeChat article editor did not load. The session may have expired.');
    }
}

async function fillField(page, selector, value) {
    return evaluate(page, `(() => {
        var el = document.querySelector(${JSON.stringify(selector)});
        if (!el) return { ok: false, reason: 'field not found' };
        el.focus();
        var proto = el.tagName === 'TEXTAREA' ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
        var setter = Object.getOwnPropertyDescriptor(proto, 'value');
        if (setter && setter.set) setter.set.call(el, ${JSON.stringify(value)});
        else el.value = ${JSON.stringify(value)};

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Open the automated browser, log in to mp.weixin.qq.com (QR scan), then rerun the command.
  2. Reuse persisted browser profile/cookies so the session survives between runs.
  3. Rerun shortly after re-login — sessions expire fast.
  4. Verify the account has permission to create drafts (subscribe/account type restrictions).

Example fix

// before
await createDraft({ title, content }); // fails with AuthRequiredError
// after
await loginWeixin(); // performs QR login first
await createDraft({ title, content });
Defensive patterns

Strategy: try-catch

Validate before calling

const href = await page.evaluate('window.location.href');
if (!/token=\d+/.test(href)) throw new Error('Not authenticated on mp.weixin.qq.com — log in first');

Type guard

function hasWeixinToken(href) {
  return typeof href === 'string' && /token=\d+/.test(href);
}

Try / catch

try {
  await createDraft(input);
} catch (err) {
  if (err instanceof AuthRequiredError) {
    console.error('Log in to the WeChat Official Account platform (QR scan), then retry');
  } else throw err;
}

Prevention

When it happens

Trigger: Running weixin create-draft while the automated browser has no valid mp.weixin.qq.com session; the login page/QR-scan page is shown instead of the dashboard so no token parameter exists.

Common situations: First run before ever logging in; WeChat Official Account sessions expire quickly (often daily); QR re-verification required after risk control; logged into a different account type without editor access.

Related errors


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