最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

google chrome - The Chromium headless page is scaled, and the resolution is not as expected - Stack Overflow

programmeradmin4浏览0评论

I am using Selenium + Chromium headless for automated testing, and the execution environment has been encapsulated into a Docker image based on Debian. Through screenshots taken during the execution, I noticed that the page is being scaled down. I set the resolution to 1920×1080, and while the page meets this resolution, the elements appear to be shrunk, with large white margins on both sides. Here is an example of a normal webpage: And here is the screenshot taken by Selenium:

My chromium variables is :

--headless
--window-size= 1920,1080
--force-device-scale-factor=1
--disable-gpu
--no-sandbox
--hide-scrollbars
--disable-dev-shm-usage
--remote-allow-origins=*

My docker file likes:

FROM debian:bookworm-slim
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        chromium \
        libglib2.0-0 \
        libnss3-dev \
        libxcb1 \
        locales \
        openjdk-17-jre \
        fontconfig \
        fonts-ipafont-gothic \
        fonts-wqy-zenhei \
        fonts-thai-tlwg \
        fonts-kacst \
        fonts-symbola \
        fonts-noto \
        fonts-freefont-ttf


Please tell me what I should do next. Thank you.

I am using Selenium + Chromium headless for automated testing, and the execution environment has been encapsulated into a Docker image based on Debian. Through screenshots taken during the execution, I noticed that the page is being scaled down. I set the resolution to 1920×1080, and while the page meets this resolution, the elements appear to be shrunk, with large white margins on both sides. Here is an example of a normal webpage: And here is the screenshot taken by Selenium:

My chromium variables is :

--headless
--window-size= 1920,1080
--force-device-scale-factor=1
--disable-gpu
--no-sandbox
--hide-scrollbars
--disable-dev-shm-usage
--remote-allow-origins=*

My docker file likes:

FROM debian:bookworm-slim
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        chromium \
        libglib2.0-0 \
        libnss3-dev \
        libxcb1 \
        locales \
        openjdk-17-jre \
        fontconfig \
        fonts-ipafont-gothic \
        fonts-wqy-zenhei \
        fonts-thai-tlwg \
        fonts-kacst \
        fonts-symbola \
        fonts-noto \
        fonts-freefont-ttf


Please tell me what I should do next. Thank you.

Share Improve this question asked Feb 14 at 5:59 linxiao yulinxiao yu 132 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

Try this to set resolution

driver.set_window_size(1920, 1080) 


driver.save_screenshot("file_name.png")
发布评论

评论列表(0)

  1. 暂无评论