PageSourceSearch

https://playwright.dev/assets/js/8b4a0820.c87d3190.js

js playwright.dev collected 2026-09-24 06:55:04 UTC 15,028 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkplaywright_dev=self.webpackChunkplaywright_dev||[]).push([["3235"],{64700(e,n,s){s.r(n),s.d(n,{metadata:()=>l,default:()=>h,frontMatter:()=>r,contentTitle:()=>o,toc:()=>t,assets:()=>i});var l=JSON.parse('{"id":"api/class-download","title":"Download","description":"Download] objects are dispatched by page via the [page.on(\'download\') event.","source":"@site/docs/api/class-download.mdx","sourceDirName":"api","slug":"/api/class-download","permalink":"/docs/next/api/class-download","draft":false,"unlisted":false,"tags":[],"version":"current","frontMatter":{"id":"class-download","title":"Download"},"sidebar":"api","previous":{"title":"Dialog","permalink":"/docs/next/api/class-dialog"},"next":{"title":"ElementHandle","permalink":"/docs/next/api/class-elementhandle"}}'),a=s(74848),d=s(28453);s(13554),s(41647),s(83137);let r={id:"class-download",title:"Download"},o,i={},t=[{value:"Methods",id:"methods",level:2},{value:"cancel",id:"download-cancel",level:3},{value:"createReadStream",id:"download-create-read-stream",level:3},{value:"delete",id:"download-delete",level:3},{value:"failure",id:"download-failure",level:3},{value:"page",id:"download-page",level:3},{value:"path",id:"download-path",level:3},{value:"saveAs",id:"download-save-as",level:3},{value:"suggestedFilename",id:"download-suggested-filename",level:3},{value:"url",id:"download-url",level:3}];function c(e){let n={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,d.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(n.p,{children:[(0,a.jsx)(n.a,{href:"/docs/next/api/class-download",title:"Download",children:"Download"})," objects are dispatched by page via the ",(0,a.jsx)(n.a,{href:"/docs/next/api/class-page#page-event-download",children:"page.on('download')"})," event."]}),"\n",(0,a.jsx)(n.p,{children:"All the downloaded files belonging to the browser context are deleted when the browser context is closed."}),"\n",(0,a.jsx)(n.p,{children:"Download event is emitted once the download starts. Download path becomes available once download completes."}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-js",children:"// Start waiting for download before clicking. Note no await.\nconst downloadPromise = page.waitForEvent('download');\nawait page.getByText('Download file').click();\nconst download = await downloadPromise;\n\n// Wait for the download process to complete and save the downloaded file somewhere.\nawait download.saveAs('/path/to/save/at/' + download.suggestedFilename());\n"})}),"\n",(0,a.jsx)(n.hr,{}),"\n",(0,a.jsx)(n.h2,{id:"methods",children:"Methods"}),"\n",(0,a.jsx)(n.h3,{id:"download-cancel",children:"cancel"}),"\n",(0,a.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.13"}),"\n",(0,a.jsx)("x-search",{children:"download.cancel"}),"\n",(0,a.jsxs)(n.p,{children:["Cancels a download. Will not fail if the download is already finished or canceled. Upon successful cancellations, ",(0,a.jsx)(n.code,{children:"download.failure()"})," would resolve to ",(0,a.jsx)(n.code,{children:"'canceled'"}),"."]}),"\n",(0,a.jsx)(n.p,{children:(0,a.jsx)(n.strong,{children:"Usage"})}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-js",children:"await download.cancel();\n"})}),"\n",(0,a.jsx)(n.p,{children:(0,a.jsx)(n.strong,{children:"Returns"})}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,a.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined",title:"void",children:"void"}),">",(0,a.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"download-cancel-return"}),(0,a.jsx)("a",{href:"#download-cancel-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,a.jsx)(n.hr,{}),"\n",(0,a.jsx)(n.h3,{id:"download-create-read-stream",children:"createReadStream"}),"\n",(0,a.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,a.jsx)("x-search",{children:"download.createReadStream"}),"\n",(0,a.jsx)(n.p,{children:"Returns a readable stream for a successful download, or throws for a failed/canceled download."}),"\n",(0,a.jsx)(n.admonition,{type:"note",children:(0,a.jsxs)(n.p,{children:["If you don't need a readable stream, it's usually simpler to read the file from disk after the download completed. See ",(0,a.jsx)(n.a,{href:"/docs/next/api/class-download#download-path",children:"download.path()"}),"."]})}),"\n",(0,a.jsx)(n.p,{children:(0,a.jsx)(n.strong,{children:"Usage"})}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-js",children:"await download.createReadStream();\n"})}),"\n",(0,a.jsx)(n.p,{children:(0,a.jsx)(n.strong,{children:"Returns"})}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,a.jsx)(n.a,{href:"https://nodejs.org/api/stream.html#stream_class_stream_readable",title:"Readable",children:"Readable"}),">",(0,a.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"download-create-read-stream-return"}),(0,a.jsx)("a",{href:"#download-create-read-stream-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,a.jsx)(n.hr,{}),"\n",(0,a.jsx)(n.h3,{id:"download-delete",children:"delete"}),"\n",(0,a.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,a.jsx)("x-search",{children:"download.delete"}),"\n",(0,a.jsx)(n.p,{children:"Deletes the downloaded file. Will wait for the download to finish if necessary."}),"\n",(0,a.jsx)(n.p,{children:(0,a.jsx)(n.strong,{children:"Usage"})}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-js",children:"await download.delete();\n"})}),"\n",(0,a.jsx)(n.p,{children:(0,a.jsx)(n.strong,{children:"Returns"})}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,a.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined",title:"void",children:"void"}),">",(0,a.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"download-delete-return"}),(0,a.jsx)("a",{href:"#download-delete-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,a.jsx)(n.hr,{}),"\n",(0,a.jsx)(n.h3,{id:"download-failure",children:"failure"}),"\n",(0,a.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,a.jsx)("x-search",{children:"download.failure"}),"\n",(0,a.jsx)(n.p,{children:"Returns download error if any. Will wait for the download to finish if necessary."}),"\n",(0,a.jsx)(n.p,{children:(0,a.jsx)(n.strong,{children:"Usage"})}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-js",children:"await download.failure();\n"})}),"\n",(0,a.jsx)(n.p,{children:(0,a.jsx)(n.strong,{children:"Returns"})}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,a.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null",title:"null",children:"null"})," | ",(0,a.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),">",(0,a.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"download-failure-return"}),(0,a.jsx)("a",{href:"#download-failure-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,a.jsx)(n.hr,{}),"\n",(0,a.jsx)(n.h3,{id:"download-page",children:"page"}),"\n",(0,a.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.12"}),"\n",(0,a.jsx)("x-search",{children:"download.page"}),"\n",(0,a.jsx)(n.p,{children:"Get the page that the download belongs to."}),"\n",(0,a.jsx)(n.p,{children:(0,a.jsx)(n.strong,{children:"Usage"})}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-js",children:"download.page(
1);\n"})}),"\n",(0,a.jsx)(n.p,{children:(0,a.jsx)(n.strong,{children:"Returns"})}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.a,{href:"/docs/next/api/class-page",title:"Page",children:"Page"}),(0,a.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"download-page-return"}),(0,a.jsx)("a",{href:"#download-page-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,a.jsx)(n.hr,{}),"\n",(0,a.jsx)(n.h3,{id:"download-path",children:"path"}),"\n",(0,a.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,a.jsx)("x-search",{children:"download.path"}),"\n",(0,a.jsx)(n.p,{children:"Returns path to the downloaded file for a successful download, or throws for a failed/canceled download. The method will wait for the download to finish if necessary. The method throws when connected remotely."}),"\n",(0,a.jsxs)(n.p,{children:["Note that the download's file name is a random GUID, use ",(0,a.jsx)(n.a,{href:"/docs/next/api/class-download#download-suggested-filename",children:"download.suggestedFilename()"})," to get suggested file name."]}),"\n",(0,a.jsx)(n.p,{children:(0,a.jsx)(n.strong,{children:"Usage"})}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-js",children:"await download.path();\n"})}),"\n",(0,a.jsx)(n.p,{children:(0,a.jsx)(n.strong,{children:"Returns"})}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,a.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),">",(0,a.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"download-path-return"}),(0,a.jsx)("a",{href:"#download-path-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,a.jsx)(n.hr,{}),"\n",(0,a.jsx)(n.h3,{id:"download-save-as",children:"saveAs"}),"\n",(0,a.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,a.jsx)("x-search",{children:"download.saveAs"}),"\n",(0,a.jsx)(n.p,{children:"Copy the download to a user-specified path. It is safe to call this method while the download is still in progress. Will wait for the download to finish if necessary."}),"\n",(0,a.jsx)(n.p,{children:(0,a.jsx)(n.strong,{children:"Usage"})}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-js",children:"await download.saveAs('/path/to/save/at/' + download.suggestedFilename());\n"})}),"\n",(0,a.jsx)(n.p,{children:(0,a.jsx)(n.strong,{children:"Arguments"})}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:["\n",(0,a.jsxs)(n.p,{children:[(0,a.jsx)(n.code,{children:"path"})," ",(0,a.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),(0,a.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"download-save-as-option-path"}),(0,a.jsx)("a",{href:"#download-save-as-option-path",class:"list-anchor",children:"#"})]}),"\n",(0,a.jsx)(n.p,{children:"Path where the download should be copied."}),"\n"]}),"\n"]}),"\n",(0,a.jsx)(n.p,{children:(0,a.jsx)(n.strong,{children:"Returns"})}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,a.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined",title:"void",children:"void"}),">",(0,a.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"download-save-as-return"}),(0,a.jsx)("a",{href:"#download-save-as-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,a.jsx)(n.hr,{}),"\n",(0,a.jsx)(n.h3,{id:"download-suggested-filename",children:"suggestedFilename"}),"\n",(0,a.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,a.jsx)("x-search",{children:"download.suggestedFilename"}),"\n",(0,a.jsxs)(n.p,{children:["Returns suggested filename for this download. It is typically computed by the browser from the ",(0,a.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition",children:(0,a.jsx)(n.code,{children:"Content-Disposition"})})," response header or the ",(0,a.jsx)(n.code,{children:"download"})," attribute. See the spec on ",(0,a.jsx)(n.a,{href:"https://html.spec.whatwg.org/#downloading-resources",children:"whatwg"}
1),". Different browsers can use different logic for computing it."]}),"\n",(0,a.jsx)(n.p,{children:(0,a.jsx)(n.strong,{children:"Usage"})}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-js",children:"download.suggestedFilename();\n"})}),"\n",(0,a.jsx)(n.p,{children:(0,a.jsx)(n.strong,{children:"Returns"})}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),(0,a.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"download-suggested-filename-return"}),(0,a.jsx)("a",{href:"#download-suggested-filename-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,a.jsx)(n.hr,{}),"\n",(0,a.jsx)(n.h3,{id:"download-url",children:"url"}),"\n",(0,a.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,a.jsx)("x-search",{children:"download.url"}),"\n",(0,a.jsx)(n.p,{children:"Returns downloaded url."}),"\n",(0,a.jsx)(n.p,{children:(0,a.jsx)(n.strong,{children:"Usage"})}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-js",children:"download.url();\n"})}),"\n",(0,a.jsx)(n.p,{children:(0,a.jsx)(n.strong,{children:"Returns"})}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),(0,a.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"download-url-return"}),(0,a.jsx)("a",{href:"#download-url-return",class:"list-anchor",children:"#"})]}),"\n"]})]})}function h(e={}){let{wrapper:n}={...(0,d.R)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(c,{...e})}):c(e)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.