PageSourceSearch

https://playwright.dev/assets/js/f6d6eda1.6af5366b.js

js playwright.dev collected 2026-09-24 06:53:44 UTC 3,553 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkplaywright_dev=self.webpackChunkplaywright_dev||[]).push([["1445"],{35752(e,o,n){n.r(o),n.d(o,{metadata:()=>a,default:()=>h,frontMatter:()=>i,contentTitle:()=>l,toc:()=>r,assets:()=>s});var a=JSON.parse('{"id":"downloads","title":"Downloads","description":"Introduction","source":"@site/docs/downloads.mdx","sourceDirName":".","slug":"/downloads","permalink":"/docs/next/downloads","draft":false,"unlisted":false,"tags":[],"version":"current","frontMatter":{"id":"downloads","title":"Downloads"},"sidebar":"docs","previous":{"title":"Dialogs","permalink":"/docs/next/dialogs"},"next":{"title":"Evaluating JavaScript","permalink":"/docs/next/evaluating"}}'),t=n(74848),d=n(28453);n(13554),n(41647),n(83137);let i={id:"downloads",title:"Downloads"},l,s={},r=[{value:"Introduction",id:"introduction",level:2},{value:"Variations",id:"variations",level:4}];function c(e){let o={a:"a",admonition:"admonition",code:"code",h2:"h2",h4:"h4",p:"p",pre:"pre",...(0,d.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(o.h2,{id:"introduction",children:"Introduction"}),"\n",(0,t.jsxs)(o.p,{children:["For every attachment downloaded by the page, ",(0,t.jsx)(o.a,{href:"/docs/next/api/class-page#page-event-download",children:"page.on('download')"})," event is emitted. All these attachments are downloaded into a temporary folder. You can obtain the download url, file name and payload stream using the ",(0,t.jsx)(o.a,{href:"/docs/next/api/class-download",title:"Download",children:"Download"})," object from the event."]}),"\n",(0,t.jsxs)(o.p,{children:["You can specify where to persist downloaded files using the ",(0,t.jsx)(o.a,{href:"/docs/next/api/class-browsertype#browser-type-launch-option-downloads-path",children:"downloadsPath"})," option in ",(0,t.jsx)(o.a,{href:"/docs/next/api/class-browsertype#browser-type-launch",children:"browserType.launch()"}),"."]}),"\n",(0,t.jsx)(o.admonition,{type:"note",children:(0,t.jsx)(o.p,{children:"Downloaded files are deleted when the browser context that produced them is closed."})}),"\n",(0,t.jsx)(o.p,{children:"Here is the simplest way to handle the file download:"}),"\n",(0,t.jsx)(o.pre,{children:(0,t.jsx)(o.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,t.jsx)(o.h4,{id:"variations",children:"Variations"}),"\n",(0,t.jsx)(o.p,{children:"If you have no idea what initiates the download, you can still handle the event:"}),"\n",(0,t.jsx)(o.pre,{children:(0,t.jsx)(o.code,{className:"language-js",children:"page.on('download', download => download.path().then(console.log));\n"})}),"\n",(0,t.jsx)(o.p,{children:"Note that handling the event forks the control flow and makes the script harder to follow. Your scenario might end while you are downloading a file since your main control flow is not awaiting for this operation to resolve."}),"\n",(0,t.jsx)(o.admonition,{type:"note",children:(0,t.jsxs)(o.p,{children:["For uploading files, see the ",(0,t.jsx)(o.a,{href:"/docs/next/input#upload-files",children:"uploading files"})," section."]})})]})}function h(e={}){let{wrapper:o}={...(0,d.R)(),...e.components};return o?(0,t.jsx)(o,{...e,children:(0,t.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.