Class: Playwright::Download
- Inherits:
-
PlaywrightApi
- Object
- PlaywrightApi
- Playwright::Download
- 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(); “‘
“‘python async async with page.expect_download() as download_info:
await page.click("a")
download = await download_info.value # waits for download to complete path = await download.path() “‘
“‘python sync with page.expect_download() as download_info:
page.click("a")
download = download_info.value # wait for download to complete path = 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, download events are emitted, but the actual download is not performed and user has no access to the downloaded files.
Instance Method Summary collapse
-
#delete ⇒ Object
Deletes the downloaded file.
-
#failure ⇒ Object
Returns download error if any.
-
#off(event, callback) ⇒ Object
– inherited from EventEmitter –.
-
#on(event, callback) ⇒ Object
– inherited from EventEmitter –.
-
#once(event, callback) ⇒ Object
– inherited from EventEmitter –.
-
#path ⇒ Object
Returns path to the downloaded file in case of successful download.
-
#save_as(path) ⇒ Object
Saves the download to a user-specified path.
-
#suggested_filename ⇒ Object
Returns suggested filename for this download.
-
#url ⇒ Object
Returns downloaded url.
Methods inherited from PlaywrightApi
Constructor Details
This class inherits a constructor from Playwright::PlaywrightApi
Instance Method Details
#delete ⇒ Object
Deletes the downloaded file.
41 42 43 |
# File 'lib/playwright_api/download.rb', line 41 def delete wrap_impl(@impl.delete) end |
#failure ⇒ Object
Returns download error if any.
46 47 48 |
# File 'lib/playwright_api/download.rb', line 46 def failure wrap_impl(@impl.failure) end |
#off(event, callback) ⇒ Object
– inherited from EventEmitter –
75 76 77 |
# File 'lib/playwright_api/download.rb', line 75 def off(event, callback) event_emitter_proxy.off(event, callback) end |
#on(event, callback) ⇒ Object
– inherited from EventEmitter –
87 88 89 |
# File 'lib/playwright_api/download.rb', line 87 def on(event, callback) event_emitter_proxy.on(event, callback) end |
#once(event, callback) ⇒ Object
– inherited from EventEmitter –
81 82 83 |
# File 'lib/playwright_api/download.rb', line 81 def once(event, callback) event_emitter_proxy.once(event, callback) end |
#path ⇒ Object
Returns path to the downloaded file in case of successful download.
51 52 53 |
# File 'lib/playwright_api/download.rb', line 51 def path wrap_impl(@impl.path) end |
#save_as(path) ⇒ Object
Saves the download to a user-specified path.
56 57 58 |
# File 'lib/playwright_api/download.rb', line 56 def save_as(path) wrap_impl(@impl.save_as(unwrap_impl(path))) end |
#suggested_filename ⇒ Object
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.
64 65 66 |
# File 'lib/playwright_api/download.rb', line 64 def suggested_filename wrap_impl(@impl.suggested_filename) end |
#url ⇒ Object
Returns downloaded url.
69 70 71 |
# File 'lib/playwright_api/download.rb', line 69 def url wrap_impl(@impl.url) end |