{"record":{"id":"9e77a8a53b9f3fd8","repo":"microsoft/playwright","slug":"locator-must-belong-to-the-main-frame-of-this-page","errorCode":null,"errorMessage":"Locator must belong to the main frame of this page","messagePattern":"Locator must belong to the main frame of this page","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/client/page.ts","lineNumber":429,"sourceCode":"    return await this._mainFrame.content();\n  }\n\n  async setContent(html: string, options?: channels.FrameSetContentOptions & TimeoutOptions): Promise<void> {\n    return await this._mainFrame.setContent(html, options);\n  }\n\n  async goto(url: string, options?: channels.FrameGotoOptions & TimeoutOptions): Promise<Response | null> {\n    return await this._mainFrame.goto(url, options);\n  }\n\n  async reload(options: channels.PageReloadOptions & TimeoutOptions = {}): Promise<Response | null> {\n    const waitUntil = verifyLoadState('waitUntil', options.waitUntil === undefined ? 'load' : options.waitUntil);\n    return Response.fromNullable((await this._channel.reload({ ...options, waitUntil }, this._timeoutSettings.navigationTimeout(options))).response);\n  }\n\n  async addLocatorHandler(locator: Locator, handler: (locator: Locator) => any, options: { times?: number, noWaitAfter?: boolean } = {}): Promise<void> {\n    if (locator._frame !== this._mainFrame)\n      throw new Error(`Locator must belong to the main frame of this page`);\n    if (options.times === 0)\n      return;\n    const { uid } = await this._channel.registerLocatorHandler({ selector: locator._selector, noWaitAfter: options.noWaitAfter }, kNoTimeout);\n    this._locatorHandlers.set(uid, { locator, handler, times: options.times });\n  }\n\n  private async _onLocatorHandlerTriggered(uid: number) {\n    let remove = false;\n    try {\n      const handler = this._locatorHandlers.get(uid);\n      if (handler && handler.times !== 0) {\n        if (handler.times !== undefined)\n          handler.times--;\n        await handler.handler(handler.locator);\n      }\n      remove = handler?.times === 0;\n    } finally {\n      if (remove)","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/client/page.ts#L411-L447","documentation":"Error \"Locator must belong to the main frame of this page\" thrown in microsoft/playwright.","triggerScenarios":"Thrown at packages/playwright-core/src/client/page.ts:429 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}