Skip to content

[Bug]: video.saveAs fails on windows  #30016

Closed

Description

@MordechaiHadad

Version

1.42.1

Steps to reproduce

On windows using playwright library (not testing suite) add this code:

import { chromium, devices } from "playwright";
import { access } from "fs/promises";

(async () => {
    const browser = await chromium.launch();
    const context = await browser.newContext({
        ...devices["iPhone 11"],
        recordVideo: { dir: "videos" },
    });
    const urls = [
        "https://www.google.com",
        "https://www.github.com",
        "https://www.microsoft.com",
        "https://www.stackoverflow.com",
        "https://www.npmjs.com",
    ];

    const pagePromises = urls.map(async (url) => {
        const page = await context.newPage();

        await context.route("**.jpg", (route) => route.abort());
        console.log("Visiting", url);
        await page.goto(url);
        await page.emulateMedia({ reducedMotion: "reduce" });
        await page.waitForLoadState("load");

        await page.close();
        const video = page.video();
        console.log(await video.path());
        const urlObject = new URL(url);
        await video.saveAs(
            `videos/video-${urlObject.hostname.split(".")[1]}.mp4"`
        );
    });

    await Promise.all(pagePromises);

    await context.close();
    await browser.close();
})();

Expected behavior

I expect the video name to turn from [guid].webm to video-[url.hostname].webm

Actual behavior

Despite the file existing (validated via 3 different ways, powershell list dir, playwright video.path, and using fs/promises access) I get this error:

node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

video.saveAs: ENOENT: no such file or directory, copyfile 'D:\repos\LeadLens\playwright-new\videos\56a49c38ac81cf02ae7dd81248875d35.webm' -> 'D:\repos\LeadLens\playwright-new\videos\video-google.mp4"'
    at D:\repos\LeadLens\playwright-new\async file:\D:\repos\LeadLens\playwright-new\index.js:44:9
    at D:\repos\LeadLens\playwright-new\async file:\D:\repos\LeadLens\playwright-new\index.js:49:5 {
  name: 'Error'
}

Node.js v21.5.0

Additional context

No response

Environment

System:
    OS: Windows 11 10.0.22631
    CPU: (12) x64 Intel(R) Core(TM) i5-10400F CPU @ 2.90GHz
    Memory: 6.21 GB / 15.94 GB
  Binaries:
    Node: 21.5.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.2.4 - C:\Program Files\nodejs\npm.CMD
  IDEs:
    VSCode: 1.87.2 - C:\Users\morde\AppData\Local\Programs\Microsoft VS Code\bin\code.CMD
  Languages:
    Bash: 5.1.16 - C:\Windows\system32\bash.EXE
  npmPackages:
    playwright: ^1.42.1 => 1.42.1

Activity

  1. yury-s commented on Mar 20, 2024

    @yury-s
    Member

    You have a stray " in the end of the file path (...}.mp4"). Removing it will fix the error. The error message is a misleading but this is what fs.promises.copyFile throws on Windows for such path.

  2. MordechaiHadad commented on Mar 21, 2024

    @MordechaiHadad
    Author

    well that was emberassing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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