Skip to content

[Bug]: Screenshot type is not inferred from path file extension #2955

@xianghuzhao

Description

@xianghuzhao

Version

1.54.0

Steps to reproduce

  1. Clone my repo at https://github.com/xianghuzhao/playwright-screenshot-bug
  2. uv run main.py
  3. Check the output file format file save.jpeg
  4. The actual format for this screenshot file is PNG, not inferred from file extension JPEG

Expected behavior

The file format should be JPEG:

file save.jpeg
save.jpeg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 1280x720, components 3

Actual behavior

file save.jpeg
save.jpeg: PNG image data, 1280 x 720, 8-bit/color RGB, non-interlaced

Additional context

According to the documentation:

path : Union[pathlib.Path, str, None]
The file path to save the image to. The screenshot type will be inferred from file extension.

But in the example I called the screenshot method with only path argument. The file extension is .jpeg and i got a PNG file with extension .jpeg. This behavior happens both in page screenshot and element screenshot methods.

I also tried the node.js version of playwright and everything works correctly as the doc. I did not try other languages.

I checked the source code and found that the path argument is removed and the file extension is not checked. I forked the repo and tried to give a fix here: https://github.com/xianghuzhao/playwright-python

Environment

- Operating System: [MacOS 15.6]
- CPU: [Apple M4]
- Browser: [All, Chromium, Firefox, WebKit]
- Python Version: [3.12]

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