jackwener/OpenCLI · error · CommandExecutionError

xiaohongshu/delete-note: malformed ${context} payload

Error message

xiaohongshu/delete-note: malformed ${context} payload

What it means

requireEvaluateString validates that a value returned from a page.evaluate script is a string before it is used (here for the current URL). If the browser context returned undefined, null, or a non-string, the library throws this CommandExecutionError naming the context. It protects downstream URL parsing from non-string input.

Source

Thrown at clis/xiaohongshu/delete-note.js:26

 *   3. Locate the row whose `data-impression` JSON contains the target noteId
 *   4. Click the inline `<span class="control data-del">` action
 *   5. Click "确定" in the `.d-modal-footer` confirmation modal
 *   6. Poll for the row disappearing from the list
 *
 * Requires: logged into creator.xiaohongshu.com in Chrome.
 */
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, AuthRequiredError, CliError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
import { unwrapEvaluateResult } from './shared.js';
const NOTE_MANAGER_URL = 'https://creator.xiaohongshu.com/new/note-manager';
const ROW_SETTLE_MS = 3000;
const MODAL_SETTLE_MS = 2000;
const VERIFY_TIMEOUT_MS = 10_000;
const VERIFY_POLL_MS = 1000;
const NOTE_ID_RE = /^[0-9a-f]{24}$/i;
function requireEvaluateString(payload, context) {
    if (typeof payload !== 'string') {
        throw new CommandExecutionError(`xiaohongshu/delete-note: malformed ${context} payload`);
    }
    return payload;
}
function requireEvaluateBoolean(payload, context) {
    if (typeof payload !== 'boolean') {
        throw new CommandExecutionError(`xiaohongshu/delete-note: malformed ${context} payload`);
    }
    return payload;
}
function requireEvaluateObject(payload, context) {
    if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
        throw new CommandExecutionError(`xiaohongshu/delete-note: malformed ${context} payload`);
    }
    return payload;
}
function requireActionResult(payload, context) {
    const result = requireEvaluateObject(payload, context);
    if (typeof result.ok !== 'boolean') {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Ensure the page is fully loaded on a xiaohongshu.com URL before running the delete-note command
  2. Retry the command — transient navigation can make evaluate return undefined
  3. Add navigation/selector waits to stabilize the page before evaluating
  4. Log the raw evaluate payload on failure to see what the page returned

Example fix

// before
const payload = await page.evaluate(() => location.href);
// after
await page.waitForFunction(() => location.hostname.includes('xiaohongshu.com'));
const payload = await page.evaluate(() => location.href);
Defensive patterns

Strategy: type-guard

Type guard

function isEvaluateString(v) { return typeof v === 'string'; }

Try / catch

try {
  await deleteNote({ noteId });
} catch (e) {
  if (e instanceof CommandExecutionError && /malformed .* payload/.test(e.message)) {
    // page likely navigated or evaluate failed; reload and retry once
  } else { throw e; }
}

Prevention

When it happens

Trigger: An in-page evaluate used by currentUrl returned undefined/null or a non-string — e.g. the script threw and returned undefined, the tab navigated mid-evaluate, or the evaluate ran in a context where `location.href` was not accessible.

Common situations: Page navigation or crash during evaluate; running against a non-xiaohongshu or chrome-error page; automation timing issues where the target frame was not ready.

Understand the failure class

Related errors


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