{"record":{"id":"1d519ea632af1cf2","repo":"jackwener/OpenCLI","slug":"pinterest-did-not-set-a-csrftoken-cookie-for-this","errorCode":null,"errorMessage":"Pinterest did not set a csrftoken cookie for this page","messagePattern":"Pinterest did not set a csrftoken cookie for this page","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/pinterest/utils.js","lineNumber":204,"sourceCode":"        return { __fetchError: (err && err.message) || String(err) };\n      }\n    })()\n  `;\n}\n\n/** POST a resource action ('get' | 'create' | 'update' | 'delete'); returns { data, results, bookmark }. */\nexport async function pinterestResourceFetch(page, resource, options, sourceUrl, action = 'get') {\n  const data = JSON.stringify({ options, context: {} });\n  const body = `source_url=${encodeURIComponent(sourceUrl)}&data=${encodeURIComponent(data)}`;\n  const url = `/resource/${resource}/${action}/`;\n\n  const raw = unwrapEvaluateResult(await page.evaluate(resourceFetchScript(url, body)));\n\n  if (raw?.__fetchError) {\n    throw new CommandExecutionError(`Pinterest request failed: ${raw.__fetchError}`);\n  }\n  if (raw?.__noCsrf) {\n    throw new CommandExecutionError(\n      'Pinterest did not set a csrftoken cookie for this page',\n      'Open https://www.pinterest.com in Chrome (logged in) and retry',\n    );\n  }\n  if (raw?.__httpError) {\n    const status = raw.__httpError;\n    // Reads work anonymously, so their 403 is a rejected request, not a login prompt;\n    // writes genuinely need login, so treat their 403 as auth too.\n    if (status === 401 || (WRITE_ACTIONS.has(action) && status === 403)) {\n      // Pinterest also answers 401 for writes it refuses on a logged-in session (e.g. editing the\n      // link of a scraped pin), so pass its own message through instead of only saying \"log in\".\n      throw new AuthRequiredError(\n        PINTEREST_DOMAIN,\n        raw.message\n          ? `Pinterest refused this write: ${raw.message}`\n          : 'This action requires being logged in to Pinterest in Chrome',\n      );\n    }","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/pinterest/utils.js#L186-L222","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Open https://www.pinterest.com in the attached Chrome window and log in, then retry","Verify the csrftoken cookie exists in DevTools > Application > Cookies for pinterest.com","Disable cookie-clearing extensions or use a persistent Chrome profile","Avoid incognito mode; use a normal profile with cookies enabled"],"exampleFix":"// before\nawait cmd.createPin({ boardId, ... }); // fails: no csrf yet\n// after\n// 1. open pinterest.com and log in in Chrome\nawait cmd.createPin({ boardId, ... });","handlingStrategy":"validation","validationCode":"const cookies = await getCookies('https://www.pinterest.com');\nif (!cookies.some(c => c.name === 'csrftoken')) {\n  throw new Error('Open pinterest.com in Chrome and log in first (no csrftoken cookie)');\n}","typeGuard":"null","tryCatchPattern":"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; }","preventionTips":["Always open and log into pinterest.com in the attached Chrome profile before write commands","Use a persistent (non-incognito) Chrome profile","Disable extensions that clear or block cookies","Check DevTools > Application > Cookies for csrftoken if unsure"],"tags":["csrf","auth","cookies","pinterest"],"backgroundTag":"missing-csrf-token","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}