chrome-devtools-mcp 1.8.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -908
- package/build/src/McpContext.js +38 -21
- package/build/src/McpPage.js +5 -1
- package/build/src/ToolHandler.js +15 -45
- package/build/src/bin/chrome-devtools-mcp-main.js +2 -2
- package/build/src/browser.js +5 -16
- package/build/src/config/browser-options.js +123 -0
- package/build/src/config/category-options.js +80 -0
- package/build/src/config/cli-options.js +2 -2
- package/build/src/config/mcp-options.js +46 -146
- package/build/src/daemon/utils.js +6 -0
- package/build/src/devtools/DevtoolsUtils.js +27 -21
- package/build/src/formatters/NetworkFormatter.js +5 -2
- package/build/src/index.js +168 -102
- package/build/src/telemetry/ClearcutLogger.js +5 -4
- package/build/src/third_party/THIRD_PARTY_NOTICES +5 -5
- package/build/src/third_party/bundled-packages.json +2 -2
- package/build/src/third_party/devtools-formatter-worker.js +22 -0
- package/build/src/third_party/devtools-heap-snapshot-worker.js +22 -0
- package/build/src/third_party/index.js +4467 -2755
- package/build/src/tools/ToolDefinition.js +15 -0
- package/build/src/tools/categories.js +0 -6
- package/build/src/tools/network.js +1 -1
- package/build/src/tools/pages.js +22 -7
- package/build/src/tools/performance.js +1 -0
- package/build/src/tools/screencast.js +1 -0
- package/build/src/tools/script.js +1 -0
- package/build/src/tools/slim/tools.js +41 -33
- package/build/src/utils/WaitForHelper.js +12 -1
- package/build/src/utils/url.js +73 -0
- package/build/src/version.js +1 -1
- package/package.json +4 -4
- package/skills/chrome-devtools-cli/SKILL.md +1 -7
- package/skills/cookie-debugging/SKILL.md +149 -0
- package/skills/memory-leak-debugging/SKILL.md +4 -0
|
@@ -51,6 +51,15 @@ export function viewportTransform(arg) {
|
|
|
51
51
|
const hasTouch = tags.includes('touch');
|
|
52
52
|
const isLandscape = tags.includes('landscape');
|
|
53
53
|
const [width, height, dpr] = dimensions.split('x').map(Number);
|
|
54
|
+
if (!Number.isFinite(width) || width <= 0) {
|
|
55
|
+
throw new Error(`Invalid viewport width "${width}". Expected format '<width>x<height>x<devicePixelRatio>[,mobile][,touch][,landscape]' with a positive width.`);
|
|
56
|
+
}
|
|
57
|
+
if (!Number.isFinite(height) || height <= 0) {
|
|
58
|
+
throw new Error(`Invalid viewport height "${height}". Expected format '<width>x<height>x<devicePixelRatio>[,mobile][,touch][,landscape]' with a positive height.`);
|
|
59
|
+
}
|
|
60
|
+
if (dpr !== undefined && (!Number.isFinite(dpr) || dpr <= 0)) {
|
|
61
|
+
throw new Error(`Invalid devicePixelRatio "${dpr}". Expected a positive number.`);
|
|
62
|
+
}
|
|
54
63
|
return {
|
|
55
64
|
width,
|
|
56
65
|
height,
|
|
@@ -65,6 +74,12 @@ export function geolocationTransform(arg) {
|
|
|
65
74
|
return undefined;
|
|
66
75
|
}
|
|
67
76
|
const [latitude, longitude] = arg.split(',').map(Number);
|
|
77
|
+
if (!Number.isFinite(latitude) || latitude < -90 || latitude > 90) {
|
|
78
|
+
throw new Error(`Invalid latitude "${latitude}". Latitude must be a number between -90 and 90.`);
|
|
79
|
+
}
|
|
80
|
+
if (!Number.isFinite(longitude) || longitude < -180 || longitude > 180) {
|
|
81
|
+
throw new Error(`Invalid longitude "${longitude}". Longitude must be a number between -180 and 180.`);
|
|
82
|
+
}
|
|
68
83
|
return {
|
|
69
84
|
latitude,
|
|
70
85
|
longitude,
|
|
@@ -30,10 +30,4 @@ export const labels = {
|
|
|
30
30
|
[ToolCategory.WEBMCP]: 'WebMCP',
|
|
31
31
|
[ToolCategory.PWA]: 'Progressive Web Apps',
|
|
32
32
|
};
|
|
33
|
-
export const OFF_BY_DEFAULT_CATEGORIES = [
|
|
34
|
-
ToolCategory.EXTENSIONS,
|
|
35
|
-
ToolCategory.THIRD_PARTY,
|
|
36
|
-
ToolCategory.WEBMCP,
|
|
37
|
-
ToolCategory.PWA,
|
|
38
|
-
];
|
|
39
33
|
//# sourceMappingURL=categories.js.map
|
|
@@ -76,7 +76,7 @@ export const listNetworkRequests = definePageTool({
|
|
|
76
76
|
});
|
|
77
77
|
export const getNetworkRequest = definePageTool({
|
|
78
78
|
name: 'get_network_request',
|
|
79
|
-
description: `Gets a network request by an optional reqid, if omitted returns the currently selected request in the DevTools Network panel.`,
|
|
79
|
+
description: `Gets a network request by an optional reqid, if omitted returns the currently selected request in the DevTools Network panel. Useful for inspecting request headers (including 'Cookie') and response headers (including 'Set-Cookie' and directives).`,
|
|
80
80
|
annotations: {
|
|
81
81
|
category: ToolCategory.NETWORK,
|
|
82
82
|
readOnlyHint: false,
|
package/build/src/tools/pages.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { zod } from '../third_party/index.js';
|
|
7
7
|
import { logger } from '../utils/logger.js';
|
|
8
|
+
import { validateUrl } from '../utils/url.js';
|
|
8
9
|
import { ToolCategory } from './categories.js';
|
|
9
10
|
import { CLOSE_PAGE_ERROR, definePageTool, defineTool, timeoutSchema, } from './ToolDefinition.js';
|
|
10
11
|
export const listPages = defineTool(args => {
|
|
@@ -84,7 +85,7 @@ export const closePage = defineTool({
|
|
|
84
85
|
response.setListThirdPartyDeveloperTools();
|
|
85
86
|
},
|
|
86
87
|
});
|
|
87
|
-
export const newPage = defineTool(
|
|
88
|
+
export const newPage = defineTool(args => {
|
|
88
89
|
return {
|
|
89
90
|
name: 'new_page',
|
|
90
91
|
description: `Open a new tab and load a URL. Use project URL if not specified otherwise.`,
|
|
@@ -103,12 +104,16 @@ export const newPage = defineTool(() => {
|
|
|
103
104
|
.optional()
|
|
104
105
|
.describe('If specified, the page is created in an isolated browser context with the given name. ' +
|
|
105
106
|
'Pages in the same browser context share cookies and storage. ' +
|
|
106
|
-
'Pages in different browser contexts are fully isolated.'),
|
|
107
|
+
'Pages in different browser contexts are fully isolated (useful for clean-slate testing of cookies and authentication).'),
|
|
107
108
|
...timeoutSchema,
|
|
108
109
|
},
|
|
109
110
|
blockedByDialog: false,
|
|
110
111
|
verifyFilesSchema: {},
|
|
111
112
|
handler: async (request, response, context) => {
|
|
113
|
+
validateUrl(request.params.url, {
|
|
114
|
+
javascriptEvaluation: args?.javascriptEvaluation,
|
|
115
|
+
categoryExtensions: args?.categoryExtensions,
|
|
116
|
+
});
|
|
112
117
|
const page = await context.newPage(request.params.background, request.params.isolatedContext);
|
|
113
118
|
await page.waitForEventsAfterAction(async () => {
|
|
114
119
|
await page.pptrPage.goto(request.params.url, {
|
|
@@ -120,7 +125,7 @@ export const newPage = defineTool(() => {
|
|
|
120
125
|
},
|
|
121
126
|
};
|
|
122
127
|
});
|
|
123
|
-
export const navigatePage = definePageTool(
|
|
128
|
+
export const navigatePage = definePageTool(args => {
|
|
124
129
|
return {
|
|
125
130
|
name: 'navigate_page',
|
|
126
131
|
description: `Go to a URL, or back, forward, or reload. Use project URL if not specified otherwise.`,
|
|
@@ -142,10 +147,14 @@ export const navigatePage = definePageTool(() => {
|
|
|
142
147
|
.enum(['accept', 'dismiss'])
|
|
143
148
|
.optional()
|
|
144
149
|
.describe('Whether to auto accept or beforeunload dialogs triggered by this navigation. Default is accept.'),
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
150
|
+
...(args?.javascriptEvaluation !== false
|
|
151
|
+
? {
|
|
152
|
+
initScript: zod
|
|
153
|
+
.string()
|
|
154
|
+
.optional()
|
|
155
|
+
.describe('A JavaScript script to be executed on each new document before any other scripts for the next navigation.'),
|
|
156
|
+
}
|
|
157
|
+
: {}),
|
|
149
158
|
...timeoutSchema,
|
|
150
159
|
},
|
|
151
160
|
blockedByDialog: false,
|
|
@@ -161,6 +170,12 @@ export const navigatePage = definePageTool(() => {
|
|
|
161
170
|
if (!request.params.type) {
|
|
162
171
|
request.params.type = 'url';
|
|
163
172
|
}
|
|
173
|
+
if (request.params.url) {
|
|
174
|
+
validateUrl(request.params.url, {
|
|
175
|
+
javascriptEvaluation: args?.javascriptEvaluation,
|
|
176
|
+
categoryExtensions: args?.categoryExtensions,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
164
179
|
let initScriptId;
|
|
165
180
|
if (request.params.initScript) {
|
|
166
181
|
const { identifier } = await page.pptrPage.evaluateOnNewDocument(request.params.initScript);
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { zod } from '../../third_party/index.js';
|
|
7
7
|
import { ToolCategory } from '../categories.js';
|
|
8
8
|
import { definePageTool } from '../ToolDefinition.js';
|
|
9
|
+
import { validateUrl } from '../../utils/url.js';
|
|
9
10
|
export const screenshot = definePageTool({
|
|
10
11
|
name: 'screenshot',
|
|
11
12
|
description: `Takes a screenshot`,
|
|
@@ -27,40 +28,46 @@ export const screenshot = definePageTool({
|
|
|
27
28
|
response.appendResponseLine(filepath);
|
|
28
29
|
},
|
|
29
30
|
});
|
|
30
|
-
export const navigate = definePageTool({
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
31
|
+
export const navigate = definePageTool(args => {
|
|
32
|
+
return {
|
|
33
|
+
name: 'navigate',
|
|
34
|
+
description: `Loads a URL`,
|
|
35
|
+
annotations: {
|
|
36
|
+
category: ToolCategory.NAVIGATION,
|
|
37
|
+
readOnlyHint: false,
|
|
38
|
+
},
|
|
39
|
+
schema: {
|
|
40
|
+
url: zod.string().describe('URL to navigate to'),
|
|
41
|
+
},
|
|
42
|
+
blockedByDialog: false,
|
|
43
|
+
verifyFilesSchema: {},
|
|
44
|
+
handler: async (request, response) => {
|
|
45
|
+
validateUrl(request.params.url, {
|
|
46
|
+
javascriptEvaluation: args?.javascriptEvaluation,
|
|
47
|
+
categoryExtensions: args?.categoryExtensions,
|
|
48
|
+
});
|
|
49
|
+
const page = request.page;
|
|
50
|
+
const options = {
|
|
51
|
+
timeout: 30_000,
|
|
52
|
+
};
|
|
53
|
+
const dialogHandler = (dialog) => {
|
|
54
|
+
if (dialog.type() === 'beforeunload') {
|
|
55
|
+
response.appendResponseLine(`Accepted a beforeunload dialog.`);
|
|
56
|
+
void dialog.accept();
|
|
57
|
+
// We are not going to report the dialog like regular dialogs.
|
|
58
|
+
page.clearDialog();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
page.pptrPage.on('dialog', dialogHandler);
|
|
62
|
+
try {
|
|
63
|
+
await page.pptrPage.goto(request.params.url, options);
|
|
64
|
+
response.appendResponseLine(`Navigated to ${page.pptrPage.url()}.`);
|
|
53
65
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
finally {
|
|
61
|
-
page.pptrPage.off('dialog', dialogHandler);
|
|
62
|
-
}
|
|
63
|
-
},
|
|
66
|
+
finally {
|
|
67
|
+
page.pptrPage.off('dialog', dialogHandler);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
};
|
|
64
71
|
});
|
|
65
72
|
export const evaluate = definePageTool({
|
|
66
73
|
name: 'evaluate',
|
|
@@ -68,6 +75,7 @@ export const evaluate = definePageTool({
|
|
|
68
75
|
annotations: {
|
|
69
76
|
category: ToolCategory.DEBUGGING,
|
|
70
77
|
readOnlyHint: false,
|
|
78
|
+
conditions: ['javascriptEvaluation'],
|
|
71
79
|
},
|
|
72
80
|
schema: {
|
|
73
81
|
script: zod.string().describe(`JS script to run on the page`),
|
|
@@ -187,7 +187,7 @@ export class WaitForHelper {
|
|
|
187
187
|
});
|
|
188
188
|
// A scoped AbortController used to clean up navigation probe listeners.
|
|
189
189
|
// When aborted (either after navigation detection finishes or if this.#abortController
|
|
190
|
-
// aborts), it removes
|
|
190
|
+
// aborts), it removes CDP navigation probe listeners and automatically
|
|
191
191
|
// detaches the abort listener from this.#abortController.signal.
|
|
192
192
|
const navigationAbortController = new AbortController();
|
|
193
193
|
const navigationStartedResolvers = Promise.withResolvers();
|
|
@@ -201,11 +201,22 @@ export class WaitForHelper {
|
|
|
201
201
|
}
|
|
202
202
|
navigationStartedResolvers.resolve(true);
|
|
203
203
|
};
|
|
204
|
+
const requestedNavigationListener = (event) => {
|
|
205
|
+
if (event.frameId === this.#page.mainFrame()._id) {
|
|
206
|
+
navigationStartedResolvers.resolve(true);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
204
209
|
this.#page._client().on('Page.frameStartedNavigating', navigationListener);
|
|
210
|
+
this.#page
|
|
211
|
+
._client()
|
|
212
|
+
.on('Page.frameRequestedNavigation', requestedNavigationListener);
|
|
205
213
|
navigationAbortController.signal.addEventListener('abort', () => {
|
|
206
214
|
this.#page
|
|
207
215
|
._client()
|
|
208
216
|
.off('Page.frameStartedNavigating', navigationListener);
|
|
217
|
+
this.#page
|
|
218
|
+
._client()
|
|
219
|
+
.off('Page.frameRequestedNavigation', requestedNavigationListener);
|
|
209
220
|
});
|
|
210
221
|
this.#abortController.signal.addEventListener('abort', () => {
|
|
211
222
|
navigationStartedResolvers.resolve(false);
|
package/build/src/utils/url.js
CHANGED
|
@@ -40,4 +40,77 @@ export function isLocalhost(url) {
|
|
|
40
40
|
}
|
|
41
41
|
return false;
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Determines whether a URL is allowed for navigation and page tracking.
|
|
45
|
+
*
|
|
46
|
+
* Disallowed schemes:
|
|
47
|
+
* - chrome: (except chrome://newtab/ and chrome://inspect*)
|
|
48
|
+
* - chrome-untrusted:
|
|
49
|
+
* - chrome-extension: (unless categoryExtensions is true)
|
|
50
|
+
*
|
|
51
|
+
* @param url The URL string to test.
|
|
52
|
+
* @param options Configuration specifying whether extensions are enabled.
|
|
53
|
+
* @returns true if the URL is allowed.
|
|
54
|
+
*/
|
|
55
|
+
export function isAllowedUrl(url, options) {
|
|
56
|
+
let parsed;
|
|
57
|
+
try {
|
|
58
|
+
parsed = new URL(url);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
if (parsed.protocol === 'chrome:') {
|
|
64
|
+
const host = parsed.hostname.toLowerCase();
|
|
65
|
+
const path = parsed.pathname.toLowerCase();
|
|
66
|
+
if (host === 'newtab' || host === 'new-tab-page' || host === 'inspect') {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
if (host === '' &&
|
|
70
|
+
(path === 'newtab' ||
|
|
71
|
+
path === 'new-tab-page' ||
|
|
72
|
+
path.startsWith('inspect'))) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (parsed.protocol === 'chrome:' ||
|
|
77
|
+
parsed.protocol === 'chrome-untrusted:') {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
if (!options.categoryExtensions && parsed.protocol === 'chrome-extension:') {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
const DISALLOWED_PROTOCOLS = new Set(['javascript:', 'data:', 'vbscript:']);
|
|
86
|
+
/**
|
|
87
|
+
* Validates a URL string by parsing it with `new URL` and checking for disallowed protocols and restricted schemes.
|
|
88
|
+
*
|
|
89
|
+
* @param url The URL string to validate.
|
|
90
|
+
* @param options Options object containing javascriptEvaluation and categoryExtensions.
|
|
91
|
+
* @returns The parsed URL.
|
|
92
|
+
* @throws Error if the URL does not parse with `new URL`, or if JavaScript evaluation is disabled and a disallowed URL is passed,
|
|
93
|
+
* or if navigating to a restricted scheme.
|
|
94
|
+
*/
|
|
95
|
+
export function validateUrl(url, options) {
|
|
96
|
+
const { javascriptEvaluation, categoryExtensions } = options;
|
|
97
|
+
let parsed;
|
|
98
|
+
try {
|
|
99
|
+
parsed = new URL(url);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
throw new Error(`Invalid URL: "${url}". URLs must be valid according to the URL standard.`);
|
|
103
|
+
}
|
|
104
|
+
if (javascriptEvaluation === false &&
|
|
105
|
+
DISALLOWED_PROTOCOLS.has(parsed.protocol)) {
|
|
106
|
+
throw new Error(`Navigating to ${parsed.protocol} URLs is not allowed when JavaScript evaluation is disabled.`);
|
|
107
|
+
}
|
|
108
|
+
if (!isAllowedUrl(url, { categoryExtensions })) {
|
|
109
|
+
if (parsed.protocol === 'chrome-extension:') {
|
|
110
|
+
throw new Error(`Navigating to chrome-extension: URLs is not allowed without --categoryExtensions.`);
|
|
111
|
+
}
|
|
112
|
+
throw new Error(`Navigating to ${parsed.protocol} URLs is not allowed.`);
|
|
113
|
+
}
|
|
114
|
+
return parsed;
|
|
115
|
+
}
|
|
43
116
|
//# sourceMappingURL=url.js.map
|
package/build/src/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chrome-devtools-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "MCP server for Chrome DevTools",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"build": "tsc && node scripts/post-build.ts",
|
|
16
16
|
"typecheck": "tsc --noEmit",
|
|
17
17
|
"format": "eslint --cache --fix . && prettier --write --cache .",
|
|
18
|
-
"check-format": "eslint --cache . && prettier --check --cache
|
|
18
|
+
"check-format": "eslint --cache . && prettier --check --cache .",
|
|
19
19
|
"gen": "npm run build && npm run cli:generate && npm run docs:generate && npm run update-metrics && npm run format",
|
|
20
20
|
"docs:generate": "node scripts/generate-docs.ts",
|
|
21
21
|
"start": "npm run build && node build/src/bin/chrome-devtools-mcp.js",
|
|
@@ -76,8 +76,8 @@
|
|
|
76
76
|
"globals": "^17.0.0",
|
|
77
77
|
"lighthouse": "13.4.1",
|
|
78
78
|
"prettier": "^3.6.2",
|
|
79
|
-
"puppeteer": "25.
|
|
80
|
-
"rollup": "4.62.
|
|
79
|
+
"puppeteer": "25.10.0",
|
|
80
|
+
"rollup": "4.62.5",
|
|
81
81
|
"rollup-plugin-cleanup": "^3.2.1",
|
|
82
82
|
"rollup-plugin-license": "^3.6.0",
|
|
83
83
|
"semver": "^7.7.4",
|
|
@@ -24,12 +24,7 @@ uid=1_0 RootWebArea "Example Domain" url="https://example.com/"
|
|
|
24
24
|
|
|
25
25
|
## Permissions & File Access
|
|
26
26
|
|
|
27
|
-
By default, the
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
# Start daemon with full filesystem access
|
|
31
|
-
chrome-devtools start --allowUnrestrictedPaths=true
|
|
32
|
-
```
|
|
27
|
+
By default, the CLI has full filesystem access (`--allowUnrestrictedPaths=true`), allowing file-saving parameters (`--filePath`, `--outputDirPath`) and `upload_file` to access files anywhere on the system. Pass `--allowUnrestrictedPaths=false` if you want to restrict file access to the OS temp directory.
|
|
33
28
|
|
|
34
29
|
## Command Usage
|
|
35
30
|
|
|
@@ -191,7 +186,6 @@ chrome-devtools execute_3p_developer_tool 1 "tool_name" --params '{"arg":"val"}'
|
|
|
191
186
|
|
|
192
187
|
```bash
|
|
193
188
|
chrome-devtools start # Start or restart chrome-devtools-mcp
|
|
194
|
-
chrome-devtools start --allowUnrestrictedPaths=true # Start with full filesystem access
|
|
195
189
|
chrome-devtools start --headless=false # Start with visible browser window
|
|
196
190
|
chrome-devtools status # Checks if chrome-devtools-mcp is running
|
|
197
191
|
chrome-devtools stop # Stop chrome-devtools-mcp if any
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cookie-debugging
|
|
3
|
+
description: Uses Chrome DevTools MCP for inspecting, debugging, and testing cookies, session state, authentication issues, and cookie consent compliance. Use when diagnosing 401/403 errors, authentication redirects, session expiration, Cookie/Set-Cookie header issues, cookie banner consent conformance, or third-party cookie/SameSite/Partitioned cookie warnings.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Core Concepts
|
|
7
|
+
|
|
8
|
+
### HttpOnly vs Client-Side Storage
|
|
9
|
+
|
|
10
|
+
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`)**.
|
|
11
|
+
|
|
12
|
+
- To inspect current `HttpOnly` values: Look at the `Cookie` request header of any outgoing HTTP request via `get_network_request`.
|
|
13
|
+
- To inspect how cookies were created or configured: Look at the `Set-Cookie` response header of login/auth responses.
|
|
14
|
+
- To inspect non-`HttpOnly` cookies: Use `evaluate_script` with the modern `cookieStore` API (`async () => await cookieStore.getAll()`).
|
|
15
|
+
|
|
16
|
+
### Session Strategy: Live Tab vs Isolated Context
|
|
17
|
+
|
|
18
|
+
Choose the right session environment to avoid state contamination (e.g., residual analytics or auth tokens):
|
|
19
|
+
|
|
20
|
+
| Strategy | When to Use | Setup / Teardown |
|
|
21
|
+
| :---------------------------------- | :---------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------ |
|
|
22
|
+
| **Live Tab (Active Page)** | Diagnosing an active user session, live 401/403 error, or current state. | Operates directly on the currently selected page. |
|
|
23
|
+
| **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`. |
|
|
24
|
+
|
|
25
|
+
### Client-Side Capabilities & Limitations
|
|
26
|
+
|
|
27
|
+
| Action | Client JavaScript (`cookieStore` / `document.cookie`) | DevTools Network & Context Tools |
|
|
28
|
+
| :--------------------------------------------------------------- | :---------------------------------------------------- | :------------------------------------------------------ |
|
|
29
|
+
| **Read Non-HttpOnly** | ✅ `async () => await cookieStore.getAll()` | ✅ `get_network_request` (Request `Cookie`) |
|
|
30
|
+
| **Read HttpOnly** | ❌ Blocked by browser security | ✅ `get_network_request` (Request `Cookie`) |
|
|
31
|
+
| **Inspect Attributes** (`Domain`, `Path`, `SameSite`, `Expires`) | ✅ `async () => await cookieStore.getAll()` | ✅ `get_network_request` (Response `Set-Cookie`) |
|
|
32
|
+
| **Modify / Delete Non-HttpOnly** | ✅ `async () => await cookieStore.set(...)` | N/A |
|
|
33
|
+
| **Modify / Delete HttpOnly** | ❌ **Silent failure** in JavaScript | ✅ Use `new_page(isolatedContext: ...)` for clean state |
|
|
34
|
+
|
|
35
|
+
> [!WARNING]
|
|
36
|
+
> Attempting to clear an `HttpOnly` cookie via JavaScript (`cookieStore.delete` or `document.cookie = "...; max-age=0"`) will silently fail. To test in an unauthenticated or fresh state, always spawn a new isolated context using `new_page` with `isolatedContext`.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Workflow Patterns
|
|
41
|
+
|
|
42
|
+
### 1. Diagnosing Authentication Failures & Redirects (401 / 403)
|
|
43
|
+
|
|
44
|
+
When an authenticated page request fails, returns 401/403, or redirects to login:
|
|
45
|
+
|
|
46
|
+
1. **List Recent Requests**: Call `list_network_requests` with `includePreservedRequests: true`.
|
|
47
|
+
2. **Find the Target Request**: Locate the failing request (401/403) or redirect (302/307).
|
|
48
|
+
3. **Inspect Outgoing `Cookie` Header**: Call `get_network_request` with the `reqid`.
|
|
49
|
+
- Verify if the `Cookie` header was attached and whether required tokens (e.g. `SESSION_ID`, `auth_token`) were sent.
|
|
50
|
+
4. **Trigger Active Inspection (If no recent request exists)**:
|
|
51
|
+
- If the cookie was set in a previous session and no network call is listed, trigger a request:
|
|
52
|
+
- Use `navigate_page` with `reload: true`, OR
|
|
53
|
+
- Call `evaluate_script` with `() => fetch(window.location.href)`
|
|
54
|
+
- Then call `get_network_request` on the new request to inspect the active `Cookie` header.
|
|
55
|
+
5. **Trace the Setting Request**: If the cookie is missing or rejected:
|
|
56
|
+
- Check earlier login/handshake responses for `Set-Cookie` directives:
|
|
57
|
+
- **Path mismatch**: e.g., `Path=/api` when the request is to `/`.
|
|
58
|
+
- **Domain mismatch**: e.g., `Domain=api.example.com` preventing cookies on `sub.example.com`.
|
|
59
|
+
- **Secure flag on HTTP**: `Secure` cookies are never sent over unencrypted `http://`.
|
|
60
|
+
- **SameSite blocking**: `SameSite=Strict` cookies are omitted on cross-site navigations.
|
|
61
|
+
- **Expiration**: Check if `Expires` or `Max-Age` elapsed.
|
|
62
|
+
|
|
63
|
+
### 2. Cookie Banner & Consent Conformance Testing
|
|
64
|
+
|
|
65
|
+
To verify that no non-essential or tracking cookies are set before consent or when declining:
|
|
66
|
+
|
|
67
|
+
1. **Start Clean**: Open a fresh isolated context with a dedicated name:
|
|
68
|
+
```json
|
|
69
|
+
{"url": "<PAGE_URL>", "isolatedContext": "consent-test-1"}
|
|
70
|
+
```
|
|
71
|
+
2. **Record Baseline Cookies**: Before interacting with the banner, run `evaluate_script` with `async () => await cookieStore.getAll()`.
|
|
72
|
+
3. **Inspect Premature Network Requests & Issues**:
|
|
73
|
+
- Call `list_network_requests` to ensure no third-party tracking beacons fired before consent.
|
|
74
|
+
- Call `list_console_messages` with `types: ["issue"]` to check for tracking warnings.
|
|
75
|
+
4. **Interact with Consent Banner**:
|
|
76
|
+
- Capture snapshot with `take_snapshot` to locate the "Decline" or "Reject All" button `uid`.
|
|
77
|
+
- Click the button with `click`.
|
|
78
|
+
5. **Verify Cookie Difference**:
|
|
79
|
+
- Run `evaluate_script` with `async () => await cookieStore.getAll()` after clicking to assert that only strictly necessary or consent-state cookies exist.
|
|
80
|
+
6. **Test Consent Revocation (Lifecycle Audit)**:
|
|
81
|
+
- When auditing consent withdrawal or preference changes:
|
|
82
|
+
- Locate and click the "Cookie Settings", "Manage Preferences", or footer privacy trigger (`take_snapshot` $\rightarrow$ `click`).
|
|
83
|
+
- Deselect non-essential categories or click "Revoke All" / "Save Preferences".
|
|
84
|
+
- Re-query `cookieStore.getAll()` to verify previously accepted non-essential cookies were cleared or expired.
|
|
85
|
+
- Call `list_network_requests` on subsequent actions to ensure tracking beacons are no longer fired.
|
|
86
|
+
7. **Teardown Context**: Call `close_page` when the audit is complete to prevent leftover cookies from affecting subsequent tasks.
|
|
87
|
+
|
|
88
|
+
### 3. Auditing Cookie Security, SameSite & CHIPS (Partitioned Cookies)
|
|
89
|
+
|
|
90
|
+
1. **Fast-Track: Native DevTools Issues (Recommended)**:
|
|
91
|
+
- Call `list_console_messages` with:
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"types": ["issue"],
|
|
95
|
+
"includePreservedMessages": true
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
- Check for `CookieIssue` entries, such as:
|
|
99
|
+
- `SameSiteNoneInsecure`: `SameSite=None` without `Secure`.
|
|
100
|
+
- `ThirdPartyCookiePhaseout`: Third-party cookie blocked or restricted.
|
|
101
|
+
- `SchemefulSameSite`: Cross-scheme cookie issues.
|
|
102
|
+
- `PartitionedCookies`: Invalid CHIPS partitioning attributes.
|
|
103
|
+
2. **Deep Audit: Lighthouse Third-Party Cookies**:
|
|
104
|
+
- Run `lighthouse_audit` with `mode: "navigation"` and `outputDirPath: "/tmp/lh-report"`.
|
|
105
|
+
- **Extract the specific cookie audit** without loading the full report into context:
|
|
106
|
+
```bash
|
|
107
|
+
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}))"
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 4. Client-Side Cookie Inspection & Manipulation
|
|
111
|
+
|
|
112
|
+
For client-accessible, non-`HttpOnly` cookies (e.g., UI preferences, non-sensitive feature flags):
|
|
113
|
+
|
|
114
|
+
1. **Read Cookies & Attributes**:
|
|
115
|
+
- Use the modern asynchronous Cookie Store API:
|
|
116
|
+
```js
|
|
117
|
+
async () => await cookieStore.getAll();
|
|
118
|
+
```
|
|
119
|
+
- _Fallback for insecure HTTP origins_: `() => document.cookie`.
|
|
120
|
+
2. **Set / Modify Cookie**:
|
|
121
|
+
- Set client cookie via `cookieStore`:
|
|
122
|
+
```js
|
|
123
|
+
async () =>
|
|
124
|
+
await cookieStore.set({
|
|
125
|
+
name: 'theme',
|
|
126
|
+
value: 'dark',
|
|
127
|
+
expires: Date.now() + 86400000,
|
|
128
|
+
sameSite: 'lax',
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
3. **Delete Cookie**:
|
|
132
|
+
- Clear client cookie:
|
|
133
|
+
```js
|
|
134
|
+
async () => await cookieStore.delete('theme');
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Troubleshooting
|
|
140
|
+
|
|
141
|
+
- **`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.
|
|
142
|
+
- **`evaluate_script` returns empty / unresolved Promise**: `cookieStore` methods are asynchronous. Always wrap calls with `async () => await cookieStore.getAll()`.
|
|
143
|
+
- **Cookie not visible in JavaScript**: The cookie is marked `HttpOnly`. Trigger a network request and call `get_network_request` to view it in the `Cookie` request header.
|
|
144
|
+
- **JavaScript deletion did not remove cookie**: The cookie is `HttpOnly` or requires matching `Path` and `Domain` parameters. Use a fresh `isolatedContext` with `new_page` for a clean slate.
|
|
145
|
+
- **Cookie set in response but not sent in requests**:
|
|
146
|
+
- Verify if page is `http://` while cookie specifies `Secure`.
|
|
147
|
+
- Check if `Domain` restricts subdomains.
|
|
148
|
+
- Check `list_console_messages(types: ["issue"])` for browser rejection reasons.
|
|
149
|
+
- **Residual cookies contaminating audits**: Always use `new_page` with a unique `isolatedContext` when running compliance tests, and call `close_page` when done.
|
|
@@ -7,6 +7,10 @@ description: Diagnoses and resolves memory leaks in JavaScript/Node.js applicati
|
|
|
7
7
|
|
|
8
8
|
This skill provides expert guidance and workflows for finding, diagnosing, and fixing memory leaks in JavaScript and Node.js applications using Chrome DevTools MCP tools.
|
|
9
9
|
|
|
10
|
+
## Prerequisites
|
|
11
|
+
|
|
12
|
+
Advanced memory debugging tools (`compare_heapsnapshots`, `get_heapsnapshot_details`, etc.) are only available when the server is started with the `--memoryDebugging` flag. First check if these tools are available; if not, try to read the MCP configuration file to check if `--memoryDebugging` is enabled.
|
|
13
|
+
|
|
10
14
|
## Core Principles
|
|
11
15
|
|
|
12
16
|
- **Prefer MCP memory tools:** Do NOT attempt to read raw `.heapsnapshot` files directly, as they are extremely large and will consume too many tokens. Use the Chrome DevTools MCP heap snapshot tools to summarize, compare, and inspect snapshots.
|