Uses Chrome DevTools MCP for inspecting, debugging, and testing cookies, session state, authentication issues, and cookie consent compliance. Use when diagnosin
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-cookie-debugging-9f4b4c1e4712 ,按照其中的说明把「cookie-debugging」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Cookies marked HttpOnly cannot be accessed or modified by client-side JavaScript (cookieStore or document.cookie). However, the browser automatically attaches active HttpOnly cookies to outgoing HTTP request headers (Cookie).
HttpOnly values: Look at the Cookie request header of any outgoing HTTP request via get_network_request.Set-Cookie response header of login/auth responses.HttpOnly cookies: Use evaluate_script with the modern cookieStore API (async () => await cookieStore.getAll()).Choose the right session environment to avoid state contamination (e.g., residual analytics or auth tokens):
| Strategy | When to Use | Setup / Teardown |
|---|---|---|
| Live Tab (Active Page) | Diagnosing an active user session, live 401/403 error, or current state. | Operates directly on the currently selected page. |
Clean-Slate (isolatedContext) | Testing cookie consent banners, first-time visits, or zero-cookie guarantees. | Call new_page with a unique isolatedContext (e.g. "consent-audit-1"). When finished, call close_page. |
| Action | Client JavaScript (cookieStore / document.cookie) | DevTools Network & Context Tools |
|---|---|---|
| Read Non-HttpOnly | ✅ async () => await cookieStore.getAll() | ✅ get_network_request (Request Cookie) |
| Read HttpOnly | ❌ Blocked by browser security | ✅ get_network_request (Request Cookie) |
Inspect Attributes (Domain, Path, SameSite, Expires) | ✅ async () => await cookieStore.getAll() | ✅ get_network_request (Response Set-Cookie) |
| Modify / Delete Non-HttpOnly | ✅ async () => await cookieStore.set(...) | N/A |
| Modify / Delete HttpOnly | ❌ Silent failure in JavaScript | ✅ Use new_page(isolatedContext: ...) for clean state |
[!WARNING] Attempting to clear an
HttpOnlycookie via JavaScript (cookieStore.deleteordocument.cookie = "...; max-age=0") will silently fail. To test in an unauthenticated or fresh state, always spawn a new isolated context usingnew_pagewithisolatedContext.
When an authenticated page request fails, returns 401/403, or redirects to login:
list_network_requests with includePreservedRequests: true.Cookie Header: Call get_network_request with the reqid.
Cookie header was attached and whether required tokens (e.g. SESSION_ID, auth_token) were sent.navigate_page with reload: true, ORevaluate_script with () => fetch(window.location.href)get_network_request on the new request to inspect the active Cookie header.Set-Cookie directives:
Path=/api when the request is to /.Domain=api.example.com preventing cookies on sub.example.com.Secure cookies are never sent over unencrypted http://.SameSite=Strict cookies are omitted on cross-site navigations.Expires or Max-Age elapsed.To verify that no non-essential or tracking cookies are set before consent or when declining:
{"url": "<PAGE_URL>", "isolatedContext": "consent-test-1"}
evaluate_script with async () => await cookieStore.getAll().list_network_requests to ensure no third-party tracking beacons fired before consent.list_console_messages with types: ["issue"] to check for tracking warnings.take_snapshot to locate the "Decline" or "Reject All" button uid.click.evaluate_script with async () => await cookieStore.getAll() after clicking to assert that only strictly necessary or consent-state cookies exist.take_snapshot $\rightarrow$ click).cookieStore.getAll() to verify previously accepted non-essential cookies were cleared or expired.list_network_requests on subsequent actions to ensure tracking beacons are no longer fired.close_page when the audit is complete to prevent leftover cookies from affecting subsequent tasks.list_console_messages with:
{
"types": ["issue"],
"includePreservedMessages": true
}
CookieIssue entries, such as:
SameSiteNoneInsecure: SameSite=None without Secure.ThirdPartyCookiePhaseout: Third-party cookie blocked or restricted.SchemefulSameSite: Cross-scheme cookie issues.PartitionedCookies: Invalid CHIPS partitioning attributes.lighthouse_audit with mode: "navigation" and outputDirPath: "/tmp/lh-report".node -e "const r=require('/tmp/lh-report/report.json'); const a=r.audits['third-party-cookies']; console.log(JSON.stringify({score: a?.score, displayValue: a?.displayValue, items: a?.details?.items}))"
For client-accessible, non-HttpOnly cookies (e.g., UI preferences, non-sensitive feature flags):
async () => await cookieStore.getAll();
() => document.cookie.cookieStore:
async () =>
await cookieStore.set({
name: 'theme',
value: 'dark',
expires: Date.now() + 86400000,
sameSite: 'lax',
});
async () => await cookieStore.delete('theme');
cookieStore is undefined: cookieStore requires a Secure Context (https://, localhost, or 127.0.0.1). On non-secure HTTP origins, use () => document.cookie or test over HTTPS.evaluate_script returns empty / unresolved Promise: cookieStore methods are asynchronous. Always wrap calls with async () => await cookieStore.getAll().HttpOnly. Trigger a network request and call get_network_request to view it in the Cookie request header.HttpOnly or requires matching Path and Domain parameters. Use a fresh isolatedContext with new_page for a clean slate.http:// while cookie specifies Secure.Domain restricts subdomains.list_console_messages(types: ["issue"]) for browser rejection reasons.new_page with a unique isolatedContext when running compliance tests, and call close_page when done.