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

[Bug]: Download event's saveAs fails with chromium connected over the CDP #34542

Closed
vvzz opened this issue Jan 29, 2025 · 2 comments
Closed

[Bug]: Download event's saveAs fails with chromium connected over the CDP #34542

vvzz opened this issue Jan 29, 2025 · 2 comments

Comments

@vvzz
Copy link

vvzz commented Jan 29, 2025

Version

1.49.0

Steps to reproduce

I'm running playwright in a container that is connecting to the Chrome started on the host machine like so:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-debug --remote-allow-origins="*"

I'm connecting to it from playwright roughly like so:

const { chromium } = require('playwright');

(async () => {
    const browser = await chromium.connectOverCDP('ws://host.docker.internal:9222/devtools/browser/24923805-d4d0-48de-805c-bae17bd4c386');
    const context = browser.contexts()[0] || await browser.newContext();
    const page = context.pages()[0] || await context.newPage();

    // Listen for download event
    page.on('download', async (download) => {
        const path = await download.path();
        const suggestedFilename = download.suggestedFilename();
        
        await download.saveAs("/tmp/workspaces/file.pdf");
        console.log(`Downloaded file saved as: ${savePath}`);
    });

    console.log('Connected to Chrome via CDP');


    await page.goto('https://some-test.site');
    await page.click("#downloadLink")



})();

Expected behavior

Should save the file to "/tmp/workspaces/file.pdf on the machine running playwright.

Actual behavior

An exception happens.

Error: download.saveAs: ENOENT: no such file or directory, copyfile '/tmp/playwright-artifacts-MedLPD/537add71-ff6a-4dfa-85e7-f6f2f68080f8'

Same thing happens when trying to use the stream.

After further investigation, it looks like it tries to copy the file locally(on the machine running playwright) instead of getting the file over the CDP protocol.

Additional context

Environment

System:
    OS: Linux 6.10 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
    CPU: (14) arm64 unknown
    Memory: 20.96 GB / 31.29 GB
    Container: Yes
  Binaries:
    Node: 18.19.0 - /usr/local/bin/node
    Yarn: 4.0.1 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.1 - /usr/local/share/npm-global/bin/pnpm
  IDEs:
    VSCode: 1.96.4 - /vscode/vscode-server/bin/linux-arm64/cd4ee3b1c348a13bafd8f9ad8060705f6d4b9cba/bin/remote-cli/code
  Languages:
    Bash: 5.1.4 - /bin/bash
@vvzz
Copy link
Author

vvzz commented Jan 29, 2025

Also this seems like it could be potentially related to #15999

@agg23
Copy link
Contributor

agg23 commented Jan 31, 2025

Some functionality doesn't function using CDP. You should instead use Playwright's communication protocol using connect().

@agg23 agg23 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 31, 2025
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