Skip to content

[Bug]: Playwright hangs on lazy-(not)loaded iframe #2999

@conte91

Description

@conte91

Version

1.55.0

Steps to reproduce

  1. Run this test script https://gist.github.com/conte91/2ce2d9d4ef4ff75b378e2e07df4ec68a
  2. The script spins a HTTP server that serves a page (index.html) containing an iframe. The iframe is set to lazy loading, and won't be fetched until it's displayed by clicking the html button.
  3. playwright shows an empty URL on the not-yet-loaded iframe
  4. running frame.evaluate hangs the execution
  5. Clicking on the button while the script is running (so the iframe is loaded) unblocks the execution, JS runs, script completes successfully.

Expected behavior

One of the following:

  • There's a well-defined/documented way to know that the iframe doesn't have an execution context yet and it will hang the script
  • The frame.evaluate call returns an error immediately saying the iframe doesn't "exist" yet
  • Calling frame.evaluate forces the frame to load, then executes the code

Actual behavior

Script hangs, there seems to be no way to know in advance that the iframe wasn't loaded (except for checking if the URL is empty, but that seems to be an unreliable/brittle side effect, I'm not sure is the intended way to perform this check)

Additional context

This seems to be very much related to microsoft/playwright#9675, microsoft/playwright#8943, which we have encountered in the past.

From whatwg's specs (this section) it seems to me that an iframe should never report an empty URL (a frame which hasn't loaded should maybe return about:blank?). If this behaviour is expected, then I wonder if there's a programmatic way to know in advance if the frame is loaded or not, or if a frame having an empty URL is indeed the "correct" way to know that the iframe isn't loaded (and an iframe with an empty URL can only be encountered in this scenario).

We discovered this since we have a test that runs some parsing code on google's home page. today's page shows the halloween doodle, and the test was hanging -> today's halloween doodle successfully spooked us :)

Environment

- Operating System: Ubuntu 22.04
- CPU: amd64
- Browser: Chromium, maybe others? (only tested on chromium)
- Python Version: [3.12.9]
- Other info: Also tried on other OS/stacks (e.g. arch, python 3.11), seems to make no difference

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions