Class: Playwright::Download

Inherits:
PlaywrightApi show all
Defined in:
lib/playwright_api/download.rb

Overview

‘Download` objects are dispatched by page via the [`event: Page.download`] event.

All the downloaded files belonging to the browser context are deleted when the browser context is closed. All downloaded files are deleted when the browser closes.

Download event is emitted once the download starts. Download path becomes available once download completes:

“‘js const [ download ] = await Promise.all([

page.waitForEvent('download'), // wait for download to start
page.click('a')

]); // wait for download to complete const path = await download.path(); … “‘

> NOTE Browser context must be created with the ‘acceptDownloads` set to `true` when user needs access to the downloaded content. If `acceptDownloads` is not set or set to `false`, download events are emitted, but the actual download is not performed and user has no access to the downloaded files.

Instance Method Summary collapse

Methods inherited from PlaywrightApi

from_channel_owner

Instance Method Details

#create_read_streamObject

Returns readable stream for current download or ‘null` if download failed.

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/playwright_api/download.rb', line 26

def create_read_stream
  raise NotImplementedError.new('create_read_stream is not implemented yet.')
end

#deleteObject

Deletes the downloaded file.

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/playwright_api/download.rb', line 31

def delete
  raise NotImplementedError.new('delete is not implemented yet.')
end

#failureObject

Returns download error if any.

Raises:

  • (NotImplementedError)


36
37
38
# File 'lib/playwright_api/download.rb', line 36

def failure
  raise NotImplementedError.new('failure is not implemented yet.')
end

#pathObject

Returns path to the downloaded file in case of successful download.

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/playwright_api/download.rb', line 41

def path
  raise NotImplementedError.new('path is not implemented yet.')
end

#save_as(path) ⇒ Object

Saves the download to a user-specified path.

Raises:

  • (NotImplementedError)


46
47
48
# File 'lib/playwright_api/download.rb', line 46

def save_as(path)
  raise NotImplementedError.new('save_as is not implemented yet.')
end

#suggested_filenameObject

Returns suggested filename for this download. It is typically computed by the browser from the [‘Content-Disposition`](developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition) response header or the `download` attribute. See the spec on [whatwg](html.spec.whatwg.org/#downloading-resources). Different browsers can use different logic for computing it.

Raises:

  • (NotImplementedError)


54
55
56
# File 'lib/playwright_api/download.rb', line 54

def suggested_filename
  raise NotImplementedError.new('suggested_filename is not implemented yet.')
end

#urlObject

Returns downloaded url.

Raises:

  • (NotImplementedError)


59
60
61
# File 'lib/playwright_api/download.rb', line 59

def url
  raise NotImplementedError.new('url is not implemented yet.')
end