Skip to content

[Bug]: Protocol error (Page.printToPDF): scale is outside of [0.1 - 2] range #2846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
EBDZV opened this issue May 9, 2025 · 1 comment
Closed

Comments

@EBDZV
Copy link

EBDZV commented May 9, 2025

Version

1.52.0

Steps to reproduce

In Docker:

FROM taavipall/fasta36-suite:v36.3.8

RUN apt-get update && apt-get install -y \
    ca-certificates \
    wget && \
    update-ca-certificates

RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
RUN python3 get-pip.py

RUN python3 -m pip install --upgrade pip

RUN python3 -m pip install playwright==1.52.0

RUN playwright install --with-deps

COPY . .

In a file named generate.py

import logging
import os

from playwright.sync_api import sync_playwright

with sync_playwright() as playwright:
    browser = playwright.chromium.launch(headless=True)
    context = browser.new_context()

    try:
        page = context.new_page()

        page.goto(
            "https://comparefasta.comparedatabase.org/executefasta.php?full_text_flag=1&sliding_80_flag=0&sliding_8_flag=0"
        )

        page.emulate_media(media="screen")
        page.pdf(
            path="/testing.pdf",
            print_background=True,
            scale=0.5,
            margin={
                "top": "10mm",
                "bottom": "10mm",
                "left": "25mm",
                "right": "25mm",
            },
        )

        page.close()

    except:
        raise
    finally:
        context.close()
        browser.close()

then, run through docker using

docker build -t debug -f Dockerfile .

docker run --rm -it \
  debug \
  python3 generate.py

and we get the following error:

Traceback (most recent call last):
  File "/usr/local/src/generate.py", line 18, in <module>
    page.pdf(
  File "/usr/local/lib/python3.10/dist-packages/playwright/sync_api/_generated.py", line 11703, in pdf
    self._sync(
  File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_sync_base.py", line 115, in _sync
    return task.result()
  File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_page.py", line 1140, in pdf
    encoded_binary = await self._channel.send("pdf", params)
  File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_connection.py", line 61, in send
    return await self._connection.wrap_api_call(
  File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_connection.py", line 528, in wrap_api_call
    raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None
playwright._impl._errors.Error: Page.pdf: Protocol error (Page.printToPDF): scale is outside of [0.1 - 2] range

Note that the scale parameter works when running this outside docker on a mac M1 machine. however, this seems to be a bug when running this on any windows instance. the only other reference i found online was here, which wasn't associated with playwright: https://forum.obsidian.md/t/unable-to-export-to-pdf/54877/15

Expected behavior

the pdf is created successfully with the scale factor applied

Actual behavior

Traceback (most recent call last):
  File "/usr/local/src/generate.py", line 18, in <module>
    page.pdf(
  File "/usr/local/lib/python3.10/dist-packages/playwright/sync_api/_generated.py", line 11703, in pdf
    self._sync(
  File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_sync_base.py", line 115, in _sync
    return task.result()
  File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_page.py", line 1140, in pdf
    encoded_binary = await self._channel.send("pdf", params)
  File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_connection.py", line 61, in send
    return await self._connection.wrap_api_call(
  File "/usr/local/lib/python3.10/dist-packages/playwright/_impl/_connection.py", line 528, in wrap_api_call
    raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None
playwright._impl._errors.Error: Page.pdf: Protocol error (Page.printToPDF): scale is outside of [0.1 - 2] range

Additional context

No response

Environment

- Operating System: [Ubuntu 22.04] (in docker)
- CPU: [M1] (but running in docker)
- Browser: [Chromium]
- Python Version: [3.10.1211]
- Other info:
@mxschmitt
Copy link
Member

The problem seems like that you are trying to use a amd64 container on a arm64 host. This is not supported and leads to issues like this. Docker internally will pick the matching platform but the image you are using is not available in linux/arm64 so its falling back to amd64. When changing it to this it works for me. (also without the platform):

FROM --platform=linux/arm64 mcr.microsoft.com/playwright/python:v1.52.0-noble

(Looks like something is going wrong with the QEMU user-mode binary translator Docker is using.)

I'll close it for now since this is not a Playwright bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants