jackwener/OpenCLI · error · CommandExecutionError

Could not open WeChat image upload: ${opened?.reason || 'unk

Error message

Could not open WeChat image upload: ${opened?.reason || 'unknown error'}

What it means

Thrown by uploadContentImage when the in-page script cannot find and click the editor's insert-image button (#js_editor_insertimage). The script returns { ok: false, reason: 'insert-image button not found' } and this error surfaces that reason.

Source

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

            return { ok: true };
        } catch (error) {
            return { ok: false, reason: String(error && error.message || error) };
        }
    })()`);
    if (!fallback?.ok) {
        throw new CommandExecutionError(`WeChat image upload fallback failed: ${fallback?.reason || 'unknown error'}`);
    }
}

async function uploadContentImage(page, image) {
    const previousKeys = await readCdnImageKeys(page);
    const opened = await evaluate(page, `(() => {
        var button = document.querySelector('#js_editor_insertimage');
        if (!button) return { ok: false, reason: 'insert-image button not found' };
        button.click();
        return { ok: true };
    })()`);
    if (!opened?.ok) throw new CommandExecutionError(`Could not open WeChat image upload: ${opened?.reason || 'unknown error'}`);
    await page.wait(1);

    const selected = await evaluate(page, `(() => {
        var item = document.querySelector('.js_img_dropdown_menu .tpl_dropdown_menu_item');
        if (!item) return { ok: false, reason: 'upload menu item not found' };
        item.click();
        return { ok: true };
    })()`);
    if (!selected?.ok) throw new CommandExecutionError(`Could not select WeChat image upload: ${selected?.reason || 'unknown error'}`);
    await page.wait(1);
    await injectImageFile(page, image);

    for (let attempt = 0; attempt < 15; attempt++) {
        await page.wait(2);
        const state = await evaluate(page, `(() => {
            var previous = new Set(${JSON.stringify(previousKeys)});
            var editor = document.querySelector('#ueditor_0');
            var images = editor ? Array.from(editor.querySelectorAll('img')) : [];

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-login to WeChat and confirm the article editor fully loads (title textarea visible) before uploading images.
  2. Check whether WeChat changed the insert-image button id and update the #js_editor_insertimage selector.
  3. Add a retry/wait that polls for the button for several seconds before failing.
  4. Dismiss any open modals/dialogs on the editor page before invoking the command.

Example fix

// before
var button = document.querySelector('#js_editor_insertimage');
if (!button) return { ok: false, reason: 'insert-image button not found' };
// after
var button = document.querySelector('#js_editor_insertimage, [data-role="insertimage"], .js_insertimage');
if (!button) return { ok: false, reason: 'insert-image button not found' };
button.scrollIntoView();
button.click();
Defensive patterns

Strategy: validation

Validate before calling

await page.wait(4);
const editorReady = await evaluate(page, '!!document.querySelector("textarea#title") && !!document.querySelector("#js_editor_insertimage")');
if (editorReady !== true) throw new Error('editor toolbar not ready — cannot upload images');

Type guard

function isInsertResult(v) { return typeof v === 'object' && v !== null && typeof v.ok === 'boolean' && typeof v.reason === 'string'; }

Try / catch

try {
    await createDraftCommand(opts);
} catch (e) {
    if (/Could not open WeChat image upload/i.test(e.message)) {
        console.error('insert-image button unavailable:', e.message);
        // re-login or update selector, then retry once
    }
    throw e;
}

Prevention

When it happens

Trigger: The editor toolbar is not rendered (session expired or editor didn't finish loading), WeChat renamed/removed the #js_editor_insertimage element in a front-end update, the page is showing a modal or alert that blocks the toolbar, or evaluate ran on the wrong page/frame.

Common situations: WeChat editor UI updates changing toolbar ids; command invoked on a half-loaded page; expired session landing on a login-interstitial that lacks the toolbar; headless rendering skipping toolbar initialization.

Related errors


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