jackwener/OpenCLI · error · CommandExecutionError

Xianyu publish requires Browser Bridge file upload support

Error message

Xianyu publish requires Browser Bridge file upload support

What it means

The xianyu publish flow uploads listing images through page.setFileInput, a capability provided only by Browser Bridge-backed page objects. When the connected browser mode lacks that method (e.g. a cookie/simple page adapter), the CLI aborts before touching the page. It is a hard capability check, thrown before any upload is attempted.

Source

Thrown at clis/xianyu/publish.js:420

        // 3. 选择分类(先于其他字段,因为分类可能影响表单结构)
        const categoryResult = await page.evaluate(buildSelectCategoryEvaluate(data.category));
        if (!categoryResult?.ok) {
            throw new CommandExecutionError(`Xianyu category selection failed: ${categoryResult?.reason || 'unknown-reason'}`);
        }
        await page.wait(1.5);

        // 4. 填充表单
        const fillResult = await page.evaluate(buildFillFormEvaluate(data));
        if (!fillResult?.ok) {
            const missing = Array.isArray(fillResult?.missing) ? fillResult.missing.join(', ') : 'unknown';
            throw new CommandExecutionError(`Xianyu publish form fill failed; missing fields: ${missing}`);
        }
        await page.wait(1);

        // 5. 上传图片(如果有)
        if (data.images.length > 0) {
            if (!page.setFileInput) {
                throw new CommandExecutionError('Xianyu publish requires Browser Bridge file upload support', 'Use a browser mode that supports setFileInput.');
            }
            const fileInput = await page.evaluate(buildFindFileInputSelectorEvaluate());
            if (!fileInput?.ok) {
                throw new CommandExecutionError(`Xianyu image upload input was not found: ${fileInput?.reason || 'unknown-reason'}`);
            }
            try {
                await page.setFileInput(data.images, fileInput.selector || 'input[type="file"]');
                await page.wait(3); // 等待图片上传处理
            } catch (err) {
                throw new CommandExecutionError(`Xianyu image upload failed: ${err?.message || err}`);
            }
        }

        // 6. 点击发布按钮
        const submitResult = await page.evaluate(buildSubmitEvaluate());
        if (!submitResult?.ok) {
            throw new CommandExecutionError(`Xianyu publish submit failed: ${submitResult?.reason || 'unknown-reason'}`);
        }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Run the command in a browser mode that supports setFileInput (full Browser Bridge / local browser), per the error's hint.
  2. Upgrade the Browser Bridge / opencli package to a version whose page object implements setFileInput.
  3. Retry without images (omit data.images) if the listing can be published text-only, then add images manually.

Example fix

// before: legacy page adapter without upload support
page.evaluate(...); // goto/evaluate only
// after: launch with Browser Bridge that implements setFileInput
await browserBridge.open('https://www.goofish.com', { capabilities: ['setFileInput'] });
Defensive patterns

Strategy: validation

Validate before calling

if (typeof page.setFileInput !== 'function') {
  throw new Error('Current browser mode lacks setFileInput; switch to Browser Bridge before publishing images.');
}

Prevention

When it happens

Trigger: Running `xianyu publish` with data.images.length > 0 while the resolved page object does not implement setFileInput — checked at clis/xianyu/publish.js:419 via `if (!page.setFileInput)`.

Common situations: Using a browser mode/adapter that only supports page.evaluate and goto (no file upload bridge); running through an older opencli Browser Bridge version predating setFileInput; swapping in a mock or remote page client without upload support.

Related errors


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