{"record":{"id":"4f7a180e903abc08","repo":"microsoft/playwright","slug":"unable-to-adopt-element-handle-from-a-different-do-4f7a18","errorCode":null,"errorMessage":"Unable to adopt element handle from a different document","messagePattern":"Unable to adopt element handle from a different document","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/server/chromium/crPage.ts","lineNumber":1170,"sourceCode":"      { x: quad[4] + position.x, y: quad[5] + position.y },\n      { x: quad[6] + position.x, y: quad[7] + position.y }\n    ]);\n  }\n\n  async _adoptElementHandle<T extends Node>(handle: dom.ElementHandle<T>, to: dom.FrameExecutionContext): Promise<dom.ElementHandle<T>> {\n    const nodeInfo = await this._client.send('DOM.describeNode', {\n      objectId: handle._objectId,\n    });\n    return this._adoptBackendNodeId(nodeInfo.node.backendNodeId, to) as Promise<dom.ElementHandle<T>>;\n  }\n\n  async _adoptBackendNodeId(backendNodeId: Protocol.DOM.BackendNodeId, to: dom.FrameExecutionContext): Promise<dom.ElementHandle> {\n    const result = await this._client._sendMayFail('DOM.resolveNode', {\n      backendNodeId,\n      executionContextId: (to.delegate as CRExecutionContext)._contextId,\n    });\n    if (!result || result.object.subtype === 'null')\n      throw new Error(dom.kUnableToAdoptErrorMessage);\n    return createHandle(to, result.object).asElement()!;\n  }\n}\n\nasync function emulateLocale(session: CRSession, locale: string) {\n  try {\n    await session.send('Emulation.setLocaleOverride', { locale });\n  } catch (exception) {\n    // All pages in the same renderer share locale. All such pages belong to the same\n    // context and if locale is overridden for one of them its value is the same as\n    // we are trying to set so it's not a problem.\n    if (exception.message.includes('Another locale override is already in effect'))\n      return;\n    throw exception;\n  }\n}\n\nasync function emulateTimezone(session: CRSession, timezoneId: string) {","sourceCodeStart":1152,"sourceCodeEnd":1188,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/server/chromium/crPage.ts#L1152-L1188","documentation":"Thrown by CRFrameSession._adoptBackendNodeId (crPage.ts:1170) when DOM.resolveNode returns nothing or a null subtype for the given backendNodeId + executionContextId. The node cannot be resolved into the destination context — typically because it lives in a different document that the target context cannot reach.","triggerScenarios":"Adopting an element handle across documents that do not share a frame tree (different tabs without a parent link, detached documents, OOIF cross-origin boundaries); the backend node was collected; shadow-DOM hosts that cannot be resolved into the isolated world.","commonSituations":"Passing an ElementHandle from one page into an evaluate on another; moving handles across popup windows; handles captured before a navigation that invalidated them.","solutions":["Re-resolve the element inside the destination page via a selector rather than passing a handle across documents.","Adopt within the same frame tree only; for popups, query afresh in the popup.","Discard handles after navigations and re-query them."],"exampleFix":"// before\nconst handle = await pageA.locator('h1').elementHandle();\nconst text = await pageB.evaluate(h => h.textContent, handle);\n// after\nconst text = await pageB.locator('h1').textContent();","handlingStrategy":"validation","validationCode":"// Do not pass ElementHandles across documents; re-query in the destination.\n// Instead of carrying a handle from pageA into pageB.evaluate(...):\nconst text = await pageB.locator('h1').textContent();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass an ElementHandle from one page into another page's evaluate.","Re-query elements in the destination page via selectors/locators.","Discard handles after any navigation and re-resolve them."],"tags":["element-handle","cross-frame","dom","chromium"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}