Skip to content

Commit

Permalink
fix: use ElementHandle to document.body instead of document
Browse files Browse the repository at this point in the history
Using `document` was causing a runtime error in the page as Playwright's
snapshot internals expect a proper element that can be "marked" via
`Element.setAttribute`.

See: https://github.com/microsoft/playwright/blob/20957f820d34a53003ab0722fa149c80fedec846/packages/playwright-core/src/server/trace/recorder/snapshotter.ts#L107-L109
See: #478

Fixes #478
  • Loading branch information
jrolfs committed Aug 25, 2022
1 parent 93f3d1c commit e5b3e6f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,11 @@ function createDelegateFor<T = DOMReturnType>(
export async function getDocument(_page?: Page): Promise<ElementHandle> {
// @ts-ignore
const page: Page = _page || this
const documentHandle = await page.mainFrame().evaluateHandle('document')
const documentHandle = await page.mainFrame().evaluateHandle<HTMLElement>('document.body')
const document = documentHandle.asElement()

if (!document) throw new Error('Could not find document')

return document
}

Expand Down

0 comments on commit e5b3e6f

Please sign in to comment.