jackwener/OpenCLI · error · CommandExecutionError

Pinterest did not set a csrftoken cookie for this page

Error message

Pinterest did not set a csrftoken cookie for this page

What it means

Pinterest's resource API requires the csrftoken cookie for authenticated/write requests. When the injected fetch script finds no csrftoken cookie (__noCsrf), the library throws CommandExecutionError telling you to open pinterest.com in Chrome first, because the CSRF token is only set after visiting the site in a logged-in session.

Source

Thrown at clis/pinterest/utils.js:204

        return { __fetchError: (err && err.message) || String(err) };
      }
    })()
  `;
}

/** POST a resource action ('get' | 'create' | 'update' | 'delete'); returns { data, results, bookmark }. */
export async function pinterestResourceFetch(page, resource, options, sourceUrl, action = 'get') {
  const data = JSON.stringify({ options, context: {} });
  const body = `source_url=${encodeURIComponent(sourceUrl)}&data=${encodeURIComponent(data)}`;
  const url = `/resource/${resource}/${action}/`;

  const raw = unwrapEvaluateResult(await page.evaluate(resourceFetchScript(url, body)));

  if (raw?.__fetchError) {
    throw new CommandExecutionError(`Pinterest request failed: ${raw.__fetchError}`);
  }
  if (raw?.__noCsrf) {
    throw new CommandExecutionError(
      'Pinterest did not set a csrftoken cookie for this page',
      'Open https://www.pinterest.com in Chrome (logged in) and retry',
    );
  }
  if (raw?.__httpError) {
    const status = raw.__httpError;
    // Reads work anonymously, so their 403 is a rejected request, not a login prompt;
    // writes genuinely need login, so treat their 403 as auth too.
    if (status === 401 || (WRITE_ACTIONS.has(action) && status === 403)) {
      // Pinterest also answers 401 for writes it refuses on a logged-in session (e.g. editing the
      // link of a scraped pin), so pass its own message through instead of only saying "log in".
      throw new AuthRequiredError(
        PINTEREST_DOMAIN,
        raw.message
          ? `Pinterest refused this write: ${raw.message}`
          : 'This action requires being logged in to Pinterest in Chrome',
      );
    }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Open https://www.pinterest.com in the attached Chrome window and log in, then retry
  2. Verify the csrftoken cookie exists in DevTools > Application > Cookies for pinterest.com
  3. Disable cookie-clearing extensions or use a persistent Chrome profile
  4. Avoid incognito mode; use a normal profile with cookies enabled

Example fix

// before
await cmd.createPin({ boardId, ... }); // fails: no csrf yet
// after
// 1. open pinterest.com and log in in Chrome
await cmd.createPin({ boardId, ... });
Defensive patterns

Strategy: validation

Validate before calling

const cookies = await getCookies('https://www.pinterest.com');
if (!cookies.some(c => c.name === 'csrftoken')) {
  throw new Error('Open pinterest.com in Chrome and log in first (no csrftoken cookie)');
}

Type guard

null

Try / catch

try { await cmd.createPin(args); } catch (e) { if (/csrftoken/.test(e.message)) { console.error('Open pinterest.com in Chrome, log in, then retry.'); } else throw e; }

Prevention

When it happens

Trigger: Calling a write action (create/re-pin/edit/delete) against a page.evaluate target where Pinterest never set the csrftoken cookie; running before ever loading https://www.pinterest.com in the attached Chrome profile; incognito/profile where cookies were cleared.

Common situations: Fresh Chrome profile never visited Pinterest; cookies wiped by privacy extensions or 'clear on exit' settings; running the tool right after Chrome start without opening Pinterest; third-party cookie blocking extensions.

Related errors


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