{"record":{"id":"bb0765447f7c0f23","repo":"microsoft/playwright","slug":"provide-an-object-with-a-url-path-or-content","errorCode":null,"errorMessage":"Provide an object with a `url`, `path` or `content` property","messagePattern":"Provide an object with a `url`, `path` or `content` property","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/server/frames.ts","lineNumber":1035,"sourceCode":"    url?: string,\n    content?: string,\n    type?: string,\n  }): Promise<dom.ElementHandle> {\n    return await progress.race(this._addScriptTag(params));\n  }\n\n  private async _addScriptTag(params: {\n    url?: string,\n    content?: string,\n    type?: string,\n  }): Promise<dom.ElementHandle> {\n    const {\n      url = null,\n      content = null,\n      type = ''\n    } = params;\n    if (!url && !content)\n      throw new Error('Provide an object with a `url`, `path` or `content` property');\n\n    const context = await this.mainContext();\n    return this._raceWithCSPError(async () => {\n      if (url !== null)\n        return (await context.evaluateHandle(addScriptUrl, { url, type })).asElement()!;\n      const result = (await context.evaluateHandle(addScriptContent, { content: content!, type })).asElement()!;\n      // Another round trip to the browser to ensure that we receive CSP error messages\n      // (if any) logged asynchronously in a separate task on the content main thread.\n      if (this._page.delegate.cspErrorsAsynchronousForInlineScripts)\n        await context.evaluate(() => true);\n      return result;\n    });\n\n    async function addScriptUrl(params: { url: string, type: string }): Promise<HTMLElement> {\n      const script = document.createElement('script');\n      script.src = params.url;\n      if (params.type)\n        script.type = params.type;","sourceCodeStart":1017,"sourceCodeEnd":1053,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/server/frames.ts#L1017-L1053","documentation":"Thrown by Frame._addScriptTag() when neither a url nor content property is supplied in the params object. The method destructures both with null defaults and checks if both are falsy. The message also references 'path' because the public API accepts path, but path is resolved to content by the time it reaches this server-side method.","triggerScenarios":"Calling page.addScriptTag() or frame.addScriptTag() with an empty object {}, an object missing all three properties, or with a property set to an empty string or undefined. Also when the path property is used but the file read fails before reaching this code, leaving url and content both null.","commonSituations":"Typo in property name (e.g., { src: '...' } instead of { url: '...' }). Passing a variable that is undefined at runtime. Conditionally building the params object and forgetting to set at least one branch. Using the older Puppeteer-style API where the property was named file.","solutions":["Provide at least one of { url: 'https://...' }, { content: 'console.log(1)' }, or { path: './script.js' } to addScriptTag.","Check that the variable holding the url or content is not undefined before passing it: if (scriptUrl) await page.addScriptTag({ url: scriptUrl }).","Use TypeScript with the proper types to catch missing properties at compile time."],"exampleFix":"// before\nawait page.addScriptTag({ src: 'https://cdn.example.com/lib.js' });\n\n// after\nawait page.addScriptTag({ url: 'https://cdn.example.com/lib.js' });","handlingStrategy":"validation","validationCode":"function validateScriptTagParams(params) {\n  if (!params.url && !params.content && !params.path)\n    throw new Error('addScriptTag requires url, path, or content');\n  return params;\n}","typeGuard":"function isValidScriptTagParams(params: any): params is { url: string } | { content: string } | { path: string } {\n  return typeof params.url === 'string' && params.url.length > 0\n    || typeof params.content === 'string' && params.content.length > 0\n    || typeof params.path === 'string' && params.path.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Always provide at least one of url, content, or path when calling addScriptTag.","Use TypeScript to enforce the union type at compile time.","Double-check property names: it is 'url', not 'src' or 'href'."],"tags":["addscripttag","validation","frame","script-injection"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}