{
  "format": 3,
  "id": "1.3",
  "title": "One frame: shared DOM, separate JavaScript worlds",
  "layers": {
    "server": {
      "label": "Server"
    },
    "page": {
      "label": "Page"
    },
    "browser": {
      "label": "Browser"
    },
    "fail": {
      "label": "Fail"
    }
  },
  "lanes": {
    "page": {
      "label": "LOGICAL CONTEXT RELATIONSHIPS",
      "layer": "server",
      "y": 16,
      "h": 297.2,
      "x": 16,
      "w": 997.142
    }
  },
  "frames": {
    "worlds-frame": {
      "label": "One frame",
      "showWith": [
        "main",
        "utility"
      ],
      "box": [
        54.141999999999996,
        124.6,
        367,
        76
      ]
    }
  },
  "nodes": {
    "main": {
      "label": "Main world",
      "layer": "page",
      "lane": "page",
      "box": [
        66.142,
        152.6,
        93,
        36
      ]
    },
    "utility": {
      "label": "Utility world",
      "layer": "page",
      "lane": "page",
      "box": [
        309.142,
        152.6,
        100,
        36
      ]
    },
    "globals": {
      "label": "Page globals",
      "layer": "page",
      "lane": "page",
      "box": [
        32,
        265.2,
        104,
        36
      ]
    },
    "dom": {
      "label": "Shared DOM",
      "layer": "page",
      "lane": "page",
      "box": [
        266.358,
        265.2,
        103,
        36
      ]
    },
    "navigation": {
      "label": "New document",
      "layer": "browser",
      "lane": "page",
      "box": [
        548.142,
        40,
        119,
        36
      ]
    },
    "worlds": {
      "label": "New worlds",
      "layer": "page",
      "lane": "page",
      "box": [
        559.142,
        152.6,
        97,
        36
      ]
    },
    "interrupted": {
      "label": "Evaluation fails",
      "layer": "fail",
      "lane": "page",
      "fail": true,
      "box": [
        212.142,
        40,
        120,
        36
      ]
    },
    "retry": {
      "label": "Element step retries",
      "layer": "server",
      "lane": "page",
      "box": [
        364.142,
        40,
        152,
        36
      ]
    },
    "old": {
      "label": "Old object handle",
      "layer": "page",
      "lane": "page",
      "box": [
        45.141999999999996,
        40,
        135,
        36
      ]
    },
    "fresh": {
      "label": "Fresh object handle",
      "layer": "page",
      "lane": "page",
      "box": [
        699.142,
        40,
        148,
        36
      ]
    },
    "stale": {
      "label": "Old handle fails",
      "layer": "fail",
      "lane": "page",
      "fail": true,
      "box": [
        879.142,
        40,
        122,
        36
      ]
    }
  },
  "edges": {
    "mainDOM": {
      "from": "main",
      "to": "dom",
      "label": {
        "at": [
          265.608,
          231.1
        ],
        "text": "sees DOM"
      },
      "path": "M157.71105861456482,188.6 L253.608,226.9 L297.3162593250444,265.2",
      "badge": [
        232.644235324044,
        218.52734310928648
      ]
    },
    "belongs": {
      "from": "old",
      "to": "main",
      "label": {
        "at": [
          124.642,
          118.5
        ],
        "text": "creation world"
      },
      "path": "M112.642,76 L112.642,114.3 L112.642,152.6",
      "badge": [
        112.642,
        114.3
      ]
    },
    "globals": {
      "from": "main",
      "to": "globals",
      "label": {
        "at": [
          96,
          231.1
        ],
        "text": "sees"
      },
      "path": "M103.48469982238011,188.6 L84,226.9 L84,265.2",
      "badge": [
        84,
        226.9
      ]
    },
    "dom": {
      "from": "utility",
      "to": "dom",
      "label": {
        "at": [
          371.142,
          231.1
        ],
        "text": "sees"
      },
      "path": "M359.142,188.6 L359.142,226.9 L331.0571474245115,265.2",
      "badge": [
        356.42371220324475,
        230.60699551781124
      ]
    },
    "replace": {
      "from": "navigation",
      "to": "worlds",
      "label": {
        "at": [
          619.6419999999999,
          118.5
        ],
        "text": "creates"
      },
      "path": "M607.642,76 L607.642,114.3 L607.642,152.6",
      "badge": [
        607.642,
        119.08749999999999
      ]
    }
  },
  "scenarios": [
    {
      "id": "how",
      "label": "One frame, two worlds",
      "display": {
        "counterLabel": false,
        "edges": "progressive",
        "edgeBadges": true,
        "nodeBadges": true,
        "log": "incremental"
      },
      "steps": [
        {
          "id": "one-frame-has-two-worlds",
          "title": "One frame has two worlds",
          "text": "Main and utility are JavaScript worlds inside the same frame.",
          "show": [
            "main",
            "utility"
          ],
          "current": [
            "main"
          ],
          "edges": [],
          "defs": [
            "main"
          ],
          "log": [],
          "sources": [
            {
              "label": "frames.ts:817-821",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/frames.ts#L817-L821"
            },
            {
              "label": "frames.ts:546-549",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/frames.ts#L546-L549"
            }
          ],
          "deeper": [
            {
              "title": "1.2 Contexts divide state, pages contain frame trees",
              "href": "/1-messages/1-2-browser-context-page-frame/"
            },
            {
              "title": "2.2 A locator stores the recipe, engines find the elements",
              "href": "/2-actions/2-2-locator-is-a-recipe/"
            },
            {
              "title": "2.1 Two loops behind every click",
              "href": "/2-actions/2-1-two-loops/"
            }
          ]
        },
        {
          "id": "checks-use-the-utility-world",
          "title": "Checks use the utility world",
          "text": "Playwright requests the utility context for its injected element work.",
          "show": [
            "utility"
          ],
          "current": [
            "utility"
          ],
          "edges": [],
          "defs": [
            "utility"
          ],
          "log": [],
          "sources": [
            {
              "label": "dom.ts:155-159",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/dom.ts#L155-L159"
            }
          ],
          "deeper": [
            {
              "title": "1.2 Contexts divide state, pages contain frame trees",
              "href": "/1-messages/1-2-browser-context-page-frame/"
            },
            {
              "title": "2.2 A locator stores the recipe, engines find the elements",
              "href": "/2-actions/2-2-locator-is-a-recipe/"
            },
            {
              "title": "2.1 Two loops behind every click",
              "href": "/2-actions/2-1-two-loops/"
            }
          ]
        },
        {
          "id": "the-worlds-keep-separate-globals",
          "title": "The worlds keep separate globals",
          "text": "The utility world does not see the page’s globals, such as window.app.",
          "show": [
            "globals"
          ],
          "current": [
            "globals"
          ],
          "edges": [
            "globals"
          ],
          "defs": [
            "globals"
          ],
          "log": [],
          "sources": [
            {
              "label": "selectors-register.spec.ts:96-107",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/tests/library/selectors-register.spec.ts#L96-L107"
            }
          ],
          "deeper": [
            {
              "title": "1.2 Contexts divide state, pages contain frame trees",
              "href": "/1-messages/1-2-browser-context-page-frame/"
            },
            {
              "title": "2.2 A locator stores the recipe, engines find the elements",
              "href": "/2-actions/2-2-locator-is-a-recipe/"
            },
            {
              "title": "2.1 Two loops behind every click",
              "href": "/2-actions/2-1-two-loops/"
            }
          ]
        },
        {
          "id": "both-worlds-see-the-same-dom",
          "title": "Both worlds see the same DOM",
          "text": "Some selector engines ask for the main world.",
          "show": [
            "dom"
          ],
          "current": [
            "dom"
          ],
          "edges": [
            "dom",
            "mainDOM"
          ],
          "defs": [
            "dom"
          ],
          "log": [],
          "sources": [
            {
              "label": "selectors-register.spec.ts:96-107",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/tests/library/selectors-register.spec.ts#L96-L107"
            },
            {
              "label": "crPage.ts:1227-1242",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/chromium/crPage.ts#L1227-L1242"
            },
            {
              "label": "selectors.ts:79-94",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/selectors.ts#L79-L94"
            }
          ],
          "deeper": [
            {
              "title": "1.2 Contexts divide state, pages contain frame trees",
              "href": "/1-messages/1-2-browser-context-page-frame/"
            },
            {
              "title": "2.2 A locator stores the recipe, engines find the elements",
              "href": "/2-actions/2-2-locator-is-a-recipe/"
            },
            {
              "title": "2.1 Two loops behind every click",
              "href": "/2-actions/2-1-two-loops/"
            }
          ]
        },
        {
          "id": "a-new-document-replaces-worlds",
          "title": "A new document replaces worlds",
          "text": "A same-document navigation keeps the worlds.",
          "show": [
            "navigation",
            "worlds"
          ],
          "current": [
            "navigation"
          ],
          "edges": [
            "replace"
          ],
          "defs": [
            "navigation"
          ],
          "log": [],
          "sources": [
            {
              "label": "frames.ts:1794-1804",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/frames.ts#L1794-L1804"
            },
            {
              "label": "frames.ts:1806-1817",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/frames.ts#L1806-L1817"
            },
            {
              "label": "crPage.ts:689-710",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/chromium/crPage.ts#L689-L710"
            }
          ],
          "deeper": [
            {
              "title": "1.2 Contexts divide state, pages contain frame trees",
              "href": "/1-messages/1-2-browser-context-page-frame/"
            },
            {
              "title": "2.2 A locator stores the recipe, engines find the elements",
              "href": "/2-actions/2-2-locator-is-a-recipe/"
            },
            {
              "title": "2.1 Two loops behind every click",
              "href": "/2-actions/2-1-two-loops/"
            }
          ]
        },
        {
          "id": "element-steps-can-retry",
          "title": "Element steps can retry",
          "text": "A pending evaluate fails when its context is destroyed. Playwright’s element step can retry; call your evaluate again.",
          "show": [
            "interrupted",
            "retry"
          ],
          "current": [
            "retry"
          ],
          "edges": [],
          "defs": [
            "interrupted",
            "retry"
          ],
          "code": "utility",
          "log": [],
          "sources": [
            {
              "label": "javascript.ts:72-78",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/javascript.ts#L72-L78"
            },
            {
              "label": "frames.ts:1806-1811",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/frames.ts#L1806-L1811"
            },
            {
              "label": "dom.ts:155-163",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/dom.ts#L155-L163"
            }
          ],
          "deeper": [
            {
              "title": "1.2 Contexts divide state, pages contain frame trees",
              "href": "/1-messages/1-2-browser-context-page-frame/"
            },
            {
              "title": "2.2 A locator stores the recipe, engines find the elements",
              "href": "/2-actions/2-2-locator-is-a-recipe/"
            },
            {
              "title": "2.1 Two loops behind every click",
              "href": "/2-actions/2-1-two-loops/"
            }
          ]
        },
        {
          "id": "get-a-fresh-ordinary-object-hand",
          "title": "Get a fresh ordinary object handle",
          "text": "After a new-document navigation, the old object handle remains tied to its old context. Get a new handle.",
          "show": [
            "old",
            "fresh"
          ],
          "current": [
            "fresh"
          ],
          "edges": [
            "belongs"
          ],
          "defs": [
            "old",
            "fresh"
          ],
          "code": "handles",
          "log": [],
          "sources": [
            {
              "label": "javascript.ts:281-287",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/javascript.ts#L281-L287"
            },
            {
              "label": "frames.ts:1794-1804",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/frames.ts#L1794-L1804"
            },
            {
              "label": "frames.ts:1806-1817",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/frames.ts#L1806-L1817"
            }
          ],
          "deeper": [
            {
              "title": "1.2 Contexts divide state, pages contain frame trees",
              "href": "/1-messages/1-2-browser-context-page-frame/"
            },
            {
              "title": "2.2 A locator stores the recipe, engines find the elements",
              "href": "/2-actions/2-2-locator-is-a-recipe/"
            },
            {
              "title": "2.1 Two loops behind every click",
              "href": "/2-actions/2-1-two-loops/"
            }
          ]
        }
      ]
    },
    {
      "id": "shared",
      "label": "Shared DOM",
      "display": {
        "counterLabel": true,
        "edges": "all",
        "edgeBadges": true,
        "nodeBadges": true,
        "log": "incremental"
      },
      "whole": {
        "title": "One frame, two JavaScript worlds",
        "text": "These are JavaScript worlds inside a frame."
      },
      "steps": [
        {
          "id": "your-page-evaluate-enters-the-ma",
          "title": "Your page.evaluate() enters the main world.",
          "text": "Your page.evaluate() enters the main world.",
          "show": [
            "main",
            "utility",
            "globals",
            "dom",
            "navigation",
            "worlds",
            "retry",
            "old",
            "fresh"
          ],
          "current": [
            "main"
          ],
          "edges": [],
          "defs": [
            "example00"
          ],
          "log": [],
          "sources": [
            {
              "label": "frames.ts:817-821",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/frames.ts#L817-L821"
            },
            {
              "label": "frames.ts:546-549",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/frames.ts#L546-L549"
            }
          ],
          "deeper": [
            {
              "title": "1.2 Contexts divide state, pages contain frame trees",
              "href": "/1-messages/1-2-browser-context-page-frame/"
            },
            {
              "title": "2.2 A locator stores the recipe, engines find the elements",
              "href": "/2-actions/2-2-locator-is-a-recipe/"
            },
            {
              "title": "2.1 Two loops behind every click",
              "href": "/2-actions/2-1-two-loops/"
            }
          ]
        },
        {
          "id": "the-utility-world-does-not-see-t",
          "title": "The utility world does not see the page’s globals.",
          "text": "The utility world does not see the page’s globals.",
          "show": [
            "globals"
          ],
          "current": [
            "globals"
          ],
          "edges": [
            "globals"
          ],
          "defs": [
            "example01"
          ],
          "log": [],
          "sources": [
            {
              "label": "selectors-register.spec.ts:96-107",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/tests/library/selectors-register.spec.ts#L96-L107"
            }
          ],
          "deeper": [
            {
              "title": "1.2 Contexts divide state, pages contain frame trees",
              "href": "/1-messages/1-2-browser-context-page-frame/"
            },
            {
              "title": "2.2 A locator stores the recipe, engines find the elements",
              "href": "/2-actions/2-2-locator-is-a-recipe/"
            },
            {
              "title": "2.1 Two loops behind every click",
              "href": "/2-actions/2-1-two-loops/"
            }
          ]
        },
        {
          "id": "both-worlds-see-the-same-dom-som",
          "title": "Both worlds see the same DOM. Some selectors request the main world.",
          "text": "Both worlds see the same DOM. Some selectors request the main world.",
          "show": [
            "dom"
          ],
          "current": [
            "dom"
          ],
          "edges": [],
          "defs": [
            "example02"
          ],
          "log": [],
          "sources": [
            {
              "label": "selectors-register.spec.ts:96-107",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/tests/library/selectors-register.spec.ts#L96-L107"
            },
            {
              "label": "crPage.ts:1227-1242",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/chromium/crPage.ts#L1227-L1242"
            },
            {
              "label": "selectors.ts:79-94",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/selectors.ts#L79-L94"
            }
          ],
          "deeper": [
            {
              "title": "1.2 Contexts divide state, pages contain frame trees",
              "href": "/1-messages/1-2-browser-context-page-frame/"
            },
            {
              "title": "2.2 A locator stores the recipe, engines find the elements",
              "href": "/2-actions/2-2-locator-is-a-recipe/"
            },
            {
              "title": "2.1 Two loops behind every click",
              "href": "/2-actions/2-1-two-loops/"
            }
          ]
        }
      ],
      "flow": [
        {
          "node": "main",
          "step": "your-page-evaluate-enters-the-ma",
          "log": []
        },
        {
          "node": "globals",
          "step": "the-utility-world-does-not-see-t",
          "log": [],
          "edge": "globals"
        },
        {
          "node": "dom",
          "step": "both-worlds-see-the-same-dom-som",
          "log": []
        }
      ]
    },
    {
      "id": "navigation",
      "label": "New document",
      "display": {
        "counterLabel": true,
        "edges": "all",
        "edgeBadges": true,
        "nodeBadges": true,
        "log": "incremental"
      },
      "whole": {
        "title": "A new document gets new worlds",
        "text": "A same-document navigation keeps the worlds."
      },
      "steps": [
        {
          "id": "both-kinds-of-work-begin-in-the",
          "title": "Both kinds of work begin in the old document.",
          "text": "Both kinds of work begin in the old document.",
          "show": [
            "main",
            "utility",
            "globals",
            "dom",
            "navigation",
            "worlds",
            "retry",
            "old",
            "fresh"
          ],
          "current": [
            "main"
          ],
          "edges": [],
          "defs": [
            "example10"
          ],
          "log": [],
          "sources": [
            {
              "label": "frames.ts:817-821",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/frames.ts#L817-L821"
            },
            {
              "label": "dom.ts:155-159",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/dom.ts#L155-L159"
            }
          ],
          "deeper": [
            {
              "title": "1.2 Contexts divide state, pages contain frame trees",
              "href": "/1-messages/1-2-browser-context-page-frame/"
            },
            {
              "title": "2.2 A locator stores the recipe, engines find the elements",
              "href": "/2-actions/2-2-locator-is-a-recipe/"
            },
            {
              "title": "2.1 Two loops behind every click",
              "href": "/2-actions/2-1-two-loops/"
            }
          ]
        },
        {
          "id": "the-old-evaluation-fails-playwri",
          "title": "The old evaluation fails; Playwright’s element step can retry.",
          "text": "The old evaluation fails; Playwright’s element step can retry.",
          "show": [
            "interrupted"
          ],
          "current": [
            "interrupted"
          ],
          "edges": [],
          "defs": [
            "example11"
          ],
          "log": [
            "Execution context was destroyed, most likely because of a navigation"
          ],
          "sources": [
            {
              "label": "javascript.ts:72-78",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/javascript.ts#L72-L78"
            },
            {
              "label": "frames.ts:1806-1811",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/frames.ts#L1806-L1811"
            },
            {
              "label": "dom.ts:155-163",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/dom.ts#L155-L163"
            }
          ],
          "deeper": [
            {
              "title": "1.2 Contexts divide state, pages contain frame trees",
              "href": "/1-messages/1-2-browser-context-page-frame/"
            },
            {
              "title": "2.2 A locator stores the recipe, engines find the elements",
              "href": "/2-actions/2-2-locator-is-a-recipe/"
            },
            {
              "title": "2.1 Two loops behind every click",
              "href": "/2-actions/2-1-two-loops/"
            }
          ]
        },
        {
          "id": "playwright-retries-its-element-s",
          "title": "Playwright retries its element step. Your evaluate must be called again.",
          "text": "Playwright retries its element step. Your evaluate must be called again.",
          "show": [
            "retry"
          ],
          "current": [
            "retry"
          ],
          "edges": [],
          "defs": [
            "example12"
          ],
          "code": "utility",
          "log": [
            "Execution context was destroyed, most likely because of a navigation"
          ],
          "sources": [
            {
              "label": "dom.ts:155-163",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/dom.ts#L155-L163"
            },
            {
              "label": "frames.ts:817-821",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/frames.ts#L817-L821"
            },
            {
              "label": "frames.ts:1794-1804",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/frames.ts#L1794-L1804"
            },
            {
              "label": "frames.ts:1806-1817",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/frames.ts#L1806-L1817"
            },
            {
              "label": "frames.ts:1806-1811",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/frames.ts#L1806-L1811"
            }
          ],
          "deeper": [
            {
              "title": "1.2 Contexts divide state, pages contain frame trees",
              "href": "/1-messages/1-2-browser-context-page-frame/"
            },
            {
              "title": "2.2 A locator stores the recipe, engines find the elements",
              "href": "/2-actions/2-2-locator-is-a-recipe/"
            },
            {
              "title": "2.1 Two loops behind every click",
              "href": "/2-actions/2-1-two-loops/"
            }
          ]
        }
      ],
      "flow": [
        {
          "node": "main",
          "step": "both-kinds-of-work-begin-in-the",
          "log": []
        },
        {
          "node": "interrupted",
          "step": "the-old-evaluation-fails-playwri",
          "log": [
            "Execution context was destroyed, most likely because of a navigation"
          ],
          "fail": true
        },
        {
          "node": "retry",
          "step": "playwright-retries-its-element-s",
          "log": []
        }
      ]
    },
    {
      "id": "handles",
      "label": "Fresh handle",
      "display": {
        "counterLabel": true,
        "edges": "all",
        "edgeBadges": true,
        "nodeBadges": true,
        "log": "incremental"
      },
      "whole": {
        "title": "Get a handle from the new document",
        "text": "Ordinary object handles belong to their original world."
      },
      "steps": [
        {
          "id": "make-an-ordinary-object-handle-i",
          "title": "Make an ordinary object handle in the old document.",
          "text": "Make an ordinary object handle in the old document.",
          "show": [
            "main",
            "utility",
            "globals",
            "dom",
            "navigation",
            "worlds",
            "retry",
            "old",
            "fresh"
          ],
          "current": [
            "old"
          ],
          "edges": [],
          "defs": [
            "example20"
          ],
          "code": "handles",
          "log": [],
          "sources": [
            {
              "label": "javascript.ts:281-287",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/javascript.ts#L281-L287"
            }
          ],
          "deeper": [
            {
              "title": "1.2 Contexts divide state, pages contain frame trees",
              "href": "/1-messages/1-2-browser-context-page-frame/"
            },
            {
              "title": "2.2 A locator stores the recipe, engines find the elements",
              "href": "/2-actions/2-2-locator-is-a-recipe/"
            },
            {
              "title": "2.1 Two loops behind every click",
              "href": "/2-actions/2-1-two-loops/"
            }
          ]
        },
        {
          "id": "the-new-document-replaces-the-wo",
          "title": "The new document replaces the worlds; the old handle stays old.",
          "text": "The new document replaces the worlds; the old handle stays old.",
          "show": [
            "worlds"
          ],
          "current": [
            "worlds"
          ],
          "edges": [],
          "defs": [
            "example21"
          ],
          "code": "handles",
          "log": [],
          "sources": [
            {
              "label": "frames.ts:1794-1804",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/frames.ts#L1794-L1804"
            },
            {
              "label": "frames.ts:1806-1817",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/frames.ts#L1806-L1817"
            },
            {
              "label": "javascript.ts:281-287",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/javascript.ts#L281-L287"
            }
          ],
          "deeper": [
            {
              "title": "1.2 Contexts divide state, pages contain frame trees",
              "href": "/1-messages/1-2-browser-context-page-frame/"
            },
            {
              "title": "2.2 A locator stores the recipe, engines find the elements",
              "href": "/2-actions/2-2-locator-is-a-recipe/"
            },
            {
              "title": "2.1 Two loops behind every click",
              "href": "/2-actions/2-1-two-loops/"
            }
          ]
        },
        {
          "id": "the-old-handle-fails-a-new-handl",
          "title": "The old handle fails. A new handle from the new document works.",
          "text": "The old handle fails. A new handle from the new document works.",
          "show": [
            "stale",
            "fresh"
          ],
          "current": [
            "stale",
            "fresh"
          ],
          "edges": [],
          "defs": [
            "example22"
          ],
          "code": "handles",
          "log": [
            "JSHandles can be evaluated only in the context they were created!"
          ],
          "sources": [
            {
              "label": "javascript.ts:281-287",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/javascript.ts#L281-L287"
            },
            {
              "label": "frames.ts:1794-1804",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/frames.ts#L1794-L1804"
            },
            {
              "label": "frames.ts:1806-1817",
              "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/frames.ts#L1806-L1817"
            }
          ],
          "deeper": [
            {
              "title": "1.2 Contexts divide state, pages contain frame trees",
              "href": "/1-messages/1-2-browser-context-page-frame/"
            },
            {
              "title": "2.2 A locator stores the recipe, engines find the elements",
              "href": "/2-actions/2-2-locator-is-a-recipe/"
            },
            {
              "title": "2.1 Two loops behind every click",
              "href": "/2-actions/2-1-two-loops/"
            }
          ]
        }
      ],
      "flow": [
        {
          "node": "old",
          "step": "make-an-ordinary-object-handle-i",
          "log": []
        },
        {
          "node": "worlds",
          "step": "the-new-document-replaces-the-wo",
          "log": []
        },
        {
          "node": "stale",
          "step": "the-old-handle-fails-a-new-handl",
          "log": [
            "JSHandles can be evaluated only in the context they were created!"
          ],
          "fail": true
        },
        {
          "node": "fresh",
          "step": "the-old-handle-fails-a-new-handl",
          "log": []
        }
      ]
    }
  ],
  "definitions": {
    "main": {
      "term": "Main world",
      "text": "page.evaluate() runs in the main world."
    },
    "utility": {
      "term": "Utility world",
      "text": "Playwright requests the utility context for its injected element work."
    },
    "globals": {
      "term": "Separate globals",
      "text": "The page’s globals are absent in the utility world."
    },
    "dom": {
      "term": "Shared DOM",
      "text": "Both worlds see the same DOM. Some selector engines request the main world."
    },
    "navigation": {
      "term": "Document navigation",
      "text": "A new document replaces the JavaScript worlds. A same-document navigation keeps them."
    },
    "interrupted": {
      "term": "Interrupted evaluation",
      "text": "A pending evaluation fails when its execution context is destroyed. Call your evaluate again."
    },
    "retry": {
      "term": "Element retry",
      "text": "Playwright’s element step can retry after the utility evaluation loses its context."
    },
    "old": {
      "term": "Ordinary object handles",
      "text": "An ordinary object handle belongs to the context where it was created."
    },
    "fresh": {
      "term": "Fresh handle",
      "text": "Obtain a new ordinary object handle in the new document."
    },
    "example00": {
      "term": "Example state",
      "text": "page.evaluate(); Playwright checks; One shared DOM; Separate JavaScript globals."
    },
    "example01": {
      "term": "Example state",
      "text": "window.app is visible; window.app is absent; One shared DOM; Separate JavaScript globals."
    },
    "example02": {
      "term": "Example state",
      "text": "Page variables; Separate variables; Both see the same elements; Same DOM, separate globals."
    },
    "example10": {
      "term": "Example state",
      "text": "page.evaluate() running; Element check running; Old document; Old worlds still active."
    },
    "example11": {
      "term": "Example state",
      "text": "✗ evaluate interrupted; Element step retries; New-document navigation; Old worlds destroyed."
    },
    "example12": {
      "term": "Example state",
      "text": "New main world; ✓ Element step retries; New document; Evaluate again after navigation."
    },
    "example20": {
      "term": "Example state",
      "text": "old → old main world; Old utility world; Old document; old holds { value: 1 }."
    },
    "example21": {
      "term": "Example state",
      "text": "New main world; New utility world; New-document navigation; Old handle → destroyed world."
    },
    "example22": {
      "term": "Example state",
      "text": "New main world; New utility world; New document; ✗ old fails    ✓ fresh succeeds."
    }
  },
  "code": {
    "utility": {
      "title": "Inside Playwright · dom.ts",
      "source": {
        "label": "dom.ts:155-155",
        "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/dom.ts#L155"
      },
      "lines": [
        "try {",
        "  const utility =",
        "    await this._frame.utilityContext();",
        "  return await utility.evaluate(",
        "    pageFunction,",
        "    [await utility.injectedScript(),",
        "      this, arg]",
        "  );",
        "} catch (e) {",
        "  if (this._frame.isNonRetriableError(e))",
        "    throw e;",
        "  return 'error:notconnected';",
        "}"
      ]
    },
    "handles": {
      "title": "In your test · handles after navigation",
      "lines": [
        "const old = await page.evaluateHandle(",
        "  () => ({ value: 1 }),",
        ");",
        "await page.goto('/next');",
        "// ✗ The old handle belongs to the old page",
        "await page.evaluate(x => x.value, old);",
        "// ✓ Make a new handle in the new page",
        "const fresh = await page.evaluateHandle(",
        "  () => ({ value: 2 }),",
        ");",
        "await page.evaluate(x => x.value, fresh);"
      ]
    }
  },
  "conceptScenario": "how",
  "concepts": [
    {
      "label": "Worlds in one frame",
      "layer": "page",
      "items": [
        {
          "definition": "main",
          "short": "Runs evaluation in the main world.",
          "nodes": [
            "main"
          ],
          "step": {
            "step": "one-frame-has-two-worlds"
          },
          "source": {
            "label": "frames.ts:817-821",
            "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/frames.ts#L817-L821"
          }
        },
        {
          "definition": "utility",
          "short": "Requests the utility context for injected element work.",
          "nodes": [
            "utility"
          ],
          "step": {
            "step": "checks-use-the-utility-world"
          },
          "source": {
            "label": "dom.ts:155-159",
            "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/dom.ts#L155-L159"
          }
        },
        {
          "definition": "globals",
          "short": "Isolated execution cannot see a page global.",
          "nodes": [
            "globals"
          ],
          "step": {
            "step": "the-worlds-keep-separate-globals"
          },
          "source": {
            "label": "selectors-register.spec.ts:96-107",
            "url": "https://github.com/microsoft/playwright/blob/v1.65.0/tests/library/selectors-register.spec.ts#L96-L107"
          }
        },
        {
          "definition": "dom",
          "short": "Chromium adopts a DOM node into another context.",
          "nodes": [
            "dom"
          ],
          "step": {
            "step": "both-worlds-see-the-same-dom"
          },
          "source": {
            "label": "crPage.ts:1227-1242",
            "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/chromium/crPage.ts#L1227-L1242"
          }
        }
      ]
    },
    {
      "label": "Document navigation",
      "layer": "browser",
      "items": [
        {
          "definition": "navigation",
          "short": "Context replacement destroys the existing context.",
          "nodes": [
            "navigation"
          ],
          "step": {
            "step": "a-new-document-replaces-worlds"
          },
          "source": {
            "label": "frames.ts:1794-1804",
            "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/frames.ts#L1794-L1804"
          }
        }
      ]
    },
    {
      "label": "Playwright element steps",
      "layer": "server",
      "items": [
        {
          "definition": "retry",
          "short": "A retriable utility evaluation returns error:notconnected.",
          "nodes": [
            "retry"
          ],
          "step": {
            "step": "element-steps-can-retry"
          },
          "source": {
            "label": "dom.ts:155-163",
            "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/dom.ts#L155-L163"
          }
        }
      ]
    },
    {
      "label": "Ordinary object handles",
      "layer": "page",
      "items": [
        {
          "definition": "old",
          "short": "Evaluation rejects handles from another context.",
          "nodes": [
            "old"
          ],
          "step": {
            "step": "get-a-fresh-ordinary-object-hand"
          },
          "source": {
            "label": "javascript.ts:281-287",
            "url": "https://github.com/microsoft/playwright/blob/v1.65.0/packages/playwright-core/src/server/javascript.ts#L281-L287"
          }
        }
      ]
    }
  ],
  "callouts": {
    "1": [
      "main",
      "utility"
    ],
    "2": [
      "dom",
      "globals"
    ],
    "3": [
      "navigation",
      "worlds",
      "retry",
      "interrupted"
    ],
    "4": [
      "old",
      "fresh",
      "stale"
    ]
  },
  "deeper": [
    {
      "title": "1.2 Contexts divide state, pages contain frame trees",
      "href": "/1-messages/1-2-browser-context-page-frame/",
      "why": "Frames contain these JavaScript worlds."
    },
    {
      "title": "2.2 A locator stores the recipe, engines find the elements",
      "href": "/2-actions/2-2-locator-is-a-recipe/",
      "why": "How selectors resolve elements."
    },
    {
      "title": "2.1 Two loops behind every click",
      "href": "/2-actions/2-1-two-loops/",
      "why": "How element actions retry."
    }
  ],
  "viewBox": [
    1029.142,
    329.2
  ],
  "measurement": {
    "name": "font-table",
    "labels": {
      "mainDOM": {
        "width": 50.56799999999999,
        "height": 12.6
      },
      "belongs": {
        "width": 88.49399999999999,
        "height": 12.6
      },
      "globals": {
        "width": 25.284,
        "height": 12.6
      },
      "dom": {
        "width": 25.284,
        "height": 12.6
      },
      "replace": {
        "width": 44.24699999999999,
        "height": 12.6
      }
    }
  }
}
