{"record":{"id":"c3e010312013ea61","repo":"microsoft/playwright","slug":"either-path-or-content-property-must-be-present","errorCode":null,"errorMessage":"Either path or content property must be present","messagePattern":"Either path or content property must be present","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/client/clientHelper.ts","lineNumber":51,"sourceCode":"export async function evaluationScript(fun: Function | string | { path?: string, content?: string }, arg?: any, addSourceUrl: boolean = true): Promise<string> {\n  if (typeof fun === 'function') {\n    const source = fun.toString();\n    const argString = Object.is(arg, undefined) ? 'undefined' : JSON.stringify(arg);\n    return `(${source})(${argString})`;\n  }\n  if (arg !== undefined)\n    throw new Error('Cannot evaluate a string with arguments');\n  if (isString(fun))\n    return fun;\n  if (fun.content !== undefined)\n    return fun.content;\n  if (fun.path !== undefined) {\n    let source = await fs.promises.readFile(fun.path, 'utf8');\n    if (addSourceUrl)\n      source = addSourceUrlToScript(source, fun.path);\n    return source;\n  }\n  throw new Error('Either path or content property must be present');\n}\n\nexport async function initScriptSourceWithExposedFunctions(fun: Function, arg: any, expose: (name: string, callback: Function) => Promise<void>): Promise<string> {\n  const exposePromises: Promise<void>[] = [];\n  const serialized = serializeAsCallArgument(arg, value => {\n    if (typeof value === 'function') {\n      const name = kFunctionBindingPrefix + createGuid();\n      exposePromises.push(expose(name, value));\n      return { fn: name };\n    }\n    return { fallThrough: value };\n  });\n  await Promise.all(exposePromises);\n  // Bindings backing the functions are registered through their own init scripts\n  // that are guaranteed to run first, so the controller is available here.\n  return `(${fun.toString()})(globalThis['${kBindingsControllerProperty}'].parseInitScriptArg(${JSON.stringify(serialized)}))`;\n}\n","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/client/clientHelper.ts#L33-L69","documentation":"Thrown at the end of evaluationScript() when the `fun` object form has neither `content` nor `path`. The helper accepts a function, a string, or an object { path?, content? }; reaching the final throw means none of those branches matched a usable source.","triggerScenarios":"Passing `evaluationScript({})`, or an object with typos like `{ contents: '...' }` or `{ filename: '...' }`. Both fun.content and fun.path are undefined, so execution falls through.","commonSituations":"Building the options object dynamically and omitting both keys; misreading the API and using `file`/`source` instead of `path`/`content`.","solutions":["Provide content: `evaluationScript({ content: 'window.x=1' })`.","Or provide path: `evaluationScript({ path: './init.js' })`.","Double-check key names are exactly 'path' or 'content'."],"exampleFix":"// before\nawait evaluationScript({ contents: 'window.x=1' });\n// after\nawait evaluationScript({ content: 'window.x=1' });","handlingStrategy":"validation","validationCode":"function isScriptObject(v: any): boolean {\n  return typeof v === 'object' && v !== null\n    && (typeof v.content === 'string' || typeof v.path === 'string');\n}\nif (!isFunctionScript(s) && typeof s !== 'string' && !isScriptObject(s))\n  throw new Error(\"Provide { path } or { content }.\");","typeGuard":"function hasPathOrContent(v: any): v is { path?: string; content?: string } {\n  return typeof v === 'object' && v !== null\n    && (typeof v.path === 'string' || typeof v.content === 'string');\n}","tryCatchPattern":null,"preventionTips":["Use the exact keys 'path' or 'content' (not 'file'/'contents'/'source').","Validate dynamic script-option objects before passing them."],"tags":["evaluation","script","validation"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}