Skip to content
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

Puppeteer New Headless causing the video to zoom in #79

Open
aamirv1 opened this issue Aug 23, 2023 · 2 comments
Open

Puppeteer New Headless causing the video to zoom in #79

aamirv1 opened this issue Aug 23, 2023 · 2 comments

Comments

@aamirv1
Copy link

aamirv1 commented Aug 23, 2023

  • I am submitting a bug report

  • Summary
    Puppeteer new headless is causing the video to be exported as zoomed in despite defining proper dimensions.
    I am attaching code snippet for both old and new headless along with the video exported with each of code to be able to recreate the issue.

Code and Video with old Headless


"use strict";

const puppeteer = require("puppeteer");
const { PuppeteerScreenRecorder } = require("puppeteer-screen-recorder");
const util = require("util");
const exec = util.promisify(require("child_process").exec);

(async () => {
  const browser = await puppeteer.launch();
  try {
    const page = await browser.newPage();
    await page.setViewport({ width: 1920, height: 1080, deviceScaleFactor: 2 });

    const recorder = new PuppeteerScreenRecorder(page);

    await page.goto("https://tailwindcss.com/");

    await recorder.start("video with old headless.mp4");
    await animate(page);
    await recorder.stop();
  } catch (e) {
    console.log(e);
  } finally {
    await browser.close();
  }
})();

const animate = async (page) => {
  await wait(500);
  await page.evaluate(() => {
    window.scrollBy({ top: 500, left: 0, behavior: "smooth" });
  });
  await wait(500);
  await page.evaluate(() => {
    window.scrollBy({ top: 1000, left: 0, behavior: "smooth" });
  });
  await wait(1000);
};

const wait = (ms) => new Promise((res) => setTimeout(res, ms));


video.with.old.headless.mp4

Code and Video with new Headless


"use strict";

const puppeteer = require("puppeteer");
const { PuppeteerScreenRecorder } = require("puppeteer-screen-recorder");
const util = require("util");
const exec = util.promisify(require("child_process").exec);

(async () => {
  const browser = await puppeteer.launch({ headless: "new" });
  try {
    const page = await browser.newPage();
    await page.setViewport({ width: 1920, height: 1080, deviceScaleFactor: 2 });

    const recorder = new PuppeteerScreenRecorder(page);

    await page.goto("https://tailwindcss.com/");

    await recorder.start("video with new headless.mp4");
    await animate(page);
    await recorder.stop();
  } catch (e) {
    console.log(e);
  } finally {
    await browser.close();
  }
})();

const animate = async (page) => {
  await wait(500);
  await page.evaluate(() => {
    window.scrollBy({ top: 500, left: 0, behavior: "smooth" });
  });
  await wait(500);
  await page.evaluate(() => {
    window.scrollBy({ top: 1000, left: 0, behavior: "smooth" });
  });
  await wait(1000);
};

const wait = (ms) => new Promise((res) => setTimeout(res, ms));


video.with.new.headless.mp4
@mvgiacomello
Copy link

I am having exactly the same issue on my side.

@mvgiacomello
Copy link

The workaround for this is to set the window size when creating the browser object - not just the viewport: --window-size=${width},${height}

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