MCPcopy Create free account
hub / github.com/ChromeDevTools/chrome-devtools-mcp / headerStringTransform

Function headerStringTransform

src/tools/emulation.ts:24–56  ·  view source on GitHub ↗
(
  value: string | undefined,
)

Source from the content-addressed store, hash-verified

22} from './ToolDefinition.js';
23
24function headerStringTransform(
25 value: string | undefined,
26): Record<string, string> | undefined {
27 if (value === undefined) {
28 return undefined;
29 }
30 if (value === '') {
31 return {};
32 }
33 let parsed: unknown;
34 try {
35 parsed = JSON.parse(value);
36 if (
37 typeof parsed !== 'object' ||
38 parsed === null ||
39 Array.isArray(parsed)
40 ) {
41 throw new Error('Headers must be a JSON object');
42 }
43 } catch (error) {
44 throw new Error(
45 `Invalid JSON for headers: ${error instanceof Error ? error.message : String(error)}`,
46 );
47 }
48 const headers: Record<string, string> = {};
49 for (const [key, headerValue] of Object.entries(parsed)) {
50 if (typeof headerValue !== 'string') {
51 throw new Error(`Header "${key}" must have a string value`);
52 }
53 headers[key] = headerValue;
54 }
55 return headers;
56}
57
58const throttlingOptions: [string, ...string[]] = [
59 'Offline',

Callers

nothing calls this directly

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected