Skip to content

[Feature] Allow CDP connection with custom downloadsPath #10700

Closed

Description

Currently when I'm trying to connect browser over CDP, Playwright always uses temp folder:

const artifactsDir = await fs.promises.mkdtemp(ARTIFACTS_FOLDER);

I wish to pass custom folder for downloadsPath in order to achieve access for downloaded files from Selenoid container.
This is available only if download path is equals to "/home/selenium/Downloads" (docs) which I can't set in Playwright right now.

Additionally, it would be nice if Playwright could store UUID of saved file, same as suggestedFilename property.
That would help to find a particular file via Selenoid API (docs)

Activity

  1. pavelfeldman commented on Dec 3, 2021

    @pavelfeldman
    Member

    This is unlikely to be addressed because only the launcher of the browser has control over the download folder for security reason. Raise this against Selenoid and they can come to us for options.

  2. tmarenko commented on Dec 4, 2021

    @tmarenko
    Author

    I'm not sure that I'm understanding correctly the security reason.
    If I hardcode the path to:

        const artifactsDir = '/home/selenium/Downloads';

    then it works and downloads files as intended.

    I've tried to pass Browser.setDownloadBehavior at launch and after launch with custom downloadPath but seems Playwright always uses temp folder for downloads over CDP:

    const download = new Download(page, this.options.downloadsPath || '', uuid, url, suggestedFilename);

    I'm using Python's package of Playwright so I can't easily edit source code of the problem because it's on JS server side.
    Any chances that feature could be done with new optional paramater or you still think that it's Selenoid's issue?

  3. tmarenko commented on Dec 6, 2021

    @tmarenko
    Author

    I've made these example commits to show what I've meant:
    tmarenko/playwright-python@0743e8e
    tmarenko@297d4c6

    With these kind of changes I can easily gain access to downloaded file:

    connection = playwright.chromium.connect_over_cdp(endpoint_url=f'ws://{SELENOID}/devtools/{browser.session_id}',
                                                      downloads_path="/home/selenium/Downloads")
    page = connection.new_page(accept_downloads=True)
    with page.expect_download() as download:
        page.click_on(download_locator)
    
    with open(download.value.uuid, 'wb') as download_file:
        response = requests.get(f"http://{SELENOID}/download/{browser.session_id}/{download.value.uuid}")
        download_file.write(response.content)
  4. tmarenko commented on Dec 15, 2021

    @tmarenko
    Author

    Pavel Feldman (@pavelfeldman)
    sorry to bothering you but could you review my last two comments and reply what you think about it?
    I'm really struggling to understand the security reason behind the Selenoid itself (if it has such).

  5. tmarenko commented on Mar 24, 2022

    @tmarenko
    Author

    Pavel Feldman (@pavelfeldman)
    any chances that you could review this again?

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