microsoft/playwright-python

[Bug]: playwright._impl._errors.Error: document.documentElement.getHTML is not a function

wencan opened this issue · 2 comments

Version

1.40.0

Steps to reproduce

import asyncio

from playwright.async_api import async_playwright


async def main():
    async with async_playwright() as p:
        browser = await p.firefox.launch()
        try:
            context = await browser.new_context()
            page = await context.new_page()
            try:
                await page.goto("https://baidu.com")
                await page.wait_for_load_state("load")
                await asyncio.sleep(3)
                await page.screenshot(path="screenshot.png", full_page=True)
                rendered = await page.evaluate(
                    "() => document.documentElement.getHTML()"
                )
                print(rendered)

            finally:
                await page.close()
                await context.close()
        finally:
            await browser.close()


if __name__ == "__main__":
    asyncio.run(main())

Expected behavior

ok

Actual behavior

Traceback (most recent call last):
  File "/home/wencan/Projects/pymain/prerender.py", line 30, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/wencan/Projects/pymain/prerender.py", line 17, in main
    rendered = await page.evaluate(
               ^^^^^^^^^^^^^^^^^^^^
  File "/home/wencan/.local/lib/python3.11/site-packages/playwright/async_api/_generated.py", line 8674, in evaluate
    await self._impl_obj.evaluate(
  File "/home/wencan/.local/lib/python3.11/site-packages/playwright/_impl/_page.py", line 391, in evaluate
    return await self._main_frame.evaluate(expression, arg)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/wencan/.local/lib/python3.11/site-packages/playwright/_impl/_frame.py", line 272, in evaluate
    await self._channel.send(
  File "/home/wencan/.local/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 62, in send
    return await self._connection.wrap_api_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/wencan/.local/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 492, in wrap_api_call
    return await cb()
           ^^^^^^^^^^
  File "/home/wencan/.local/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 100, in inner_send
    result = next(iter(done)).result()
             ^^^^^^^^^^^^^^^^^^^^^^^^^
playwright._impl._errors.Error: document.documentElement.getHTML is not a function
@debugger eval code line 226 > eval:1:32
evaluate@debugger eval code:233:19
@debugger eval code:1:44

Additional context

No response

Environment

- Operating System: [Debian 12]
- CPU: [arm64]
- Browser: [Chromium, Firefox]
- Python Version: [3.11]
Playwright: 1.40.0

I can't reproduce - maybe you can try on latest Playwright version v1.49?