{"record":{"id":"11bd0fc1a66fe8bf","repo":"SeleniumHQ/selenium","slug":"pass-in-a-capturescreenshotparameters-object-rece","errorCode":null,"errorMessage":"Pass in a CaptureScreenshotParameters object. Received: ${captureScreenshotParameters}","messagePattern":"Pass in a CaptureScreenshotParameters object\\. Received: (.+?)","errorType":"exception","errorClass":"InvalidArgumentError","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/browsingContext.js","lineNumber":290,"sourceCode":"    params.params = this._driver.validatePrintPageParams(options, params.params)\n\n    const response = await this.bidi.send(params)\n    return new PrintResult(response.result.data)\n  }\n\n  /**\n   * Captures a screenshot of the browsing context.\n   *\n   * @param {CaptureScreenshotParameters|undefined} [captureScreenshotParameters] - Optional parameters for capturing the screenshot.\n   * @returns {Promise<string>} - A promise that resolves to the base64-encoded string representation of the captured screenshot.\n   * @throws {InvalidArgumentError} - If the provided captureScreenshotParameters is not an instance of CaptureScreenshotParameters.\n   */\n  async captureScreenshot(captureScreenshotParameters = undefined) {\n    if (\n      captureScreenshotParameters !== undefined &&\n      !(captureScreenshotParameters instanceof CaptureScreenshotParameters)\n    ) {\n      throw new InvalidArgumentError(\n        `Pass in a CaptureScreenshotParameters object. Received: ${captureScreenshotParameters}`,\n      )\n    }\n\n    const screenshotParams = new Map()\n    screenshotParams.set('context', this._id)\n    if (captureScreenshotParameters !== undefined) {\n      captureScreenshotParameters.asMap().forEach((value, key) => {\n        screenshotParams.set(key, value)\n      })\n    }\n\n    let params = {\n      method: 'browsingContext.captureScreenshot',\n      params: Object.fromEntries(screenshotParams),\n    }\n\n    const response = await this.bidi.send(params)","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/browsingContext.js#L272-L308","documentation":"BrowsingContext.captureScreenshot() accepts an optional CaptureScreenshotParameters instance (or undefined for defaults). If a non-undefined, non-CaptureScreenshotParameters value is passed, it throws InvalidArgumentError. This guards the subsequent captureScreenshotParameters.asMap().forEach() call, which would throw a TypeError on a plain object/null. The check allows undefined (uses defaults) but rejects everything else.","triggerScenarios":"Calling captureScreenshot({ origin: 'viewport' }) with a plain object instead of a CaptureScreenshotParameters instance. Passing a Map, a JSON config object, or null (null is not undefined, so it fails). Passing parameters built for a different BiDi command.","commonSituations":"Constructing params as a plain object from config instead of using the builder class. Passing null explicitly instead of omitting the argument. Copying example code that skips the CaptureScreenshotParameters constructor.","solutions":["Build params via new CaptureScreenshotParameters().origin(...).imageFormat(...) and pass that instance, or omit the argument entirely for defaults.","If you have no custom params, call captureScreenshot() with no argument (undefined).","Never pass null; pass nothing or a real CaptureScreenshotParameters instance.","If building from config, construct the builder and set fields conditionally."],"exampleFix":"// before\nawait browsingContext.captureScreenshot({ origin: 'viewport', format: 'png' })\n\n// after\nconst params = new CaptureScreenshotParameters().origin(Origin.VIEWPORT)\nawait browsingContext.captureScreenshot(params)","handlingStrategy":"type-guard","validationCode":"if (\n  captureScreenshotParameters !== undefined &&\n  !(captureScreenshotParameters instanceof CaptureScreenshotParameters)\n) {\n  throw new TypeError('Pass a CaptureScreenshotParameters instance or omit the argument')\n}","typeGuard":"function isCaptureParams(p) {\n  return p === undefined || p instanceof CaptureScreenshotParameters\n}","tryCatchPattern":null,"preventionTips":["Build params with new CaptureScreenshotParameters().origin(...).imageFormat(...).","Omit the argument entirely for default screenshot behavior.","Never pass null; pass nothing or a real instance.","Do not construct plain config objects."],"tags":["bidi","browsing-context","screenshot","type-validation","invalid-argument"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}