{"record":{"id":"21708b836b2166c1","repo":"SeleniumHQ/selenium","slug":"msg","errorCode":null,"errorMessage":"${msg}","messagePattern":"\\$\\{msg\\}","errorType":"exception","errorClass":"InvalidArgumentError","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/browsingContext.js","lineNumber":365,"sourceCode":"            sharedId: sharedId,\n            handle: handle,\n          },\n        },\n      },\n    }\n\n    const response = await this.bidi.send(params)\n    this.checkErrorInScreenshot(response)\n    return response['result']['data']\n  }\n\n  checkErrorInScreenshot(response) {\n    if ('error' in response) {\n      const { error, msg } = response\n\n      switch (error) {\n        case 'invalid argument':\n          throw new InvalidArgumentError(msg)\n\n        case 'no such frame':\n          throw new NoSuchFrameError(msg)\n      }\n    }\n  }\n\n  /**\n   * Activates and focuses the top-level browsing context.\n   * @returns {Promise<void>} A promise that resolves when the browsing context is activated.\n   * @throws {Error} If there is an error while activating the browsing context.\n   */\n  async activate() {\n    const params = {\n      method: 'browsingContext.activate',\n      params: {\n        context: this._id,\n      },","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/browsingContext.js#L347-L383","documentation":"BrowsingContext.checkErrorInScreenshot inspects the BiDi response object; if it contains an 'error' key equal to 'invalid argument', it throws InvalidArgumentError with the server-supplied msg. This surfaces server-side validation failures from the browsingContext.captureScreenshot command — e.g. an unsupported image format, an out-of-range clip rectangle, or an invalid origin. The dynamic msg comes from the remote end (browser/driver), so its content varies.","triggerScenarios":"Requesting an image format the remote end does not support (e.g. 'webp' on an older build). Supplying a clip rectangle with negative width/height. An origin value the driver rejects. A quality value outside [0,100] that the server validates. Requesting a screenshot of a context that is not in a capturable state.","commonSituations":"Driver/browser version mismatch where a BiDi screenshot feature is unsupported. Passing quality > 100 or < 0. Clip rectangles computed from stale element geometry yielding invalid dimensions. Headless vs. headed differences in supported formats.","solutions":["Validate image format against supported values (typically 'png'/'jpeg') before sending; prefer 'png'.","Ensure clip rectangle width/height are positive finite numbers.","Keep quality within [0,100].","Upgrade the browser/driver to a version supporting the requested BiDi screenshot options.","Inspect the server msg in the caught InvalidArgumentError for the specific rejected field."],"exampleFix":"// before\nparams.imageFormat('webp', 150)\nawait browsingContext.captureScreenshot(params)\n\n// after\nparams.imageFormat('png')\nawait browsingContext.captureScreenshot(params)","handlingStrategy":"try-catch","validationCode":"const SUPPORTED = ['png', 'jpeg']\nif (type && !SUPPORTED.includes(type)) {\n  throw new Error('Unsupported screenshot image format: ' + type)\n}","typeGuard":null,"tryCatchPattern":"try {\n  data = await browsingContext.captureScreenshot(params)\n} catch (e) {\n  if (e instanceof InvalidArgumentError) {\n    // inspect e.message for the rejected field; adjust params and retry\n  } else throw e\n}","preventionTips":["Use 'png' unless jpeg compression is specifically needed.","Keep clip width/height positive and finite.","Keep quality within [0,100].","Match driver/browser version to the BiDi features you use."],"tags":["bidi","browsing-context","screenshot","server-error","invalid-argument"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}