PageSourceSearch

https://playwright.dev/assets/js/b422d3b3.03a81809.js

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

1"use strict";(self.webpackChunkplaywright_dev=self.webpackChunkplaywright_dev||[]).push([["3448"],{32729(e,s,i){i.r(s),i.d(s,{metadata:()=>n,default:()=>h,frontMatter:()=>r,contentTitle:()=>d,toc:()=>o,assets:()=>t});var n=JSON.parse('{"id":"api/class-dialog","title":"Dialog","description":"Dialog] objects are dispatched by page via the [page.on(\'dialog\') event.","source":"@site/docs/api/class-dialog.mdx","sourceDirName":"api","slug":"/api/class-dialog","permalink":"/docs/next/api/class-dialog","draft":false,"unlisted":false,"tags":[],"version":"current","frontMatter":{"id":"class-dialog","title":"Dialog"},"sidebar":"api","previous":{"title":"Debugger","permalink":"/docs/next/api/class-debugger"},"next":{"title":"Download","permalink":"/docs/next/api/class-download"}}'),l=i(74848),a=i(28453);i(13554),i(41647),i(83137);let r={id:"class-dialog",title:"Dialog"},d,t={},o=[{value:"Methods",id:"methods",level:2},{value:"accept",id:"dialog-accept",level:3},{value:"defaultValue",id:"dialog-default-value",level:3},{value:"dismiss",id:"dialog-dismiss",level:3},{value:"message",id:"dialog-message",level:3},{value:"page",id:"dialog-page",level:3},{value:"type",id:"dialog-type",level:3}];function c(e){let s={a:"a",admonition:"admonition",code:"code",em:"em",h2:"h2",h3:"h3",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,a.R)(),...e.components};return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(s.p,{children:[(0,l.jsx)(s.a,{href:"/docs/next/api/class-dialog",title:"Dialog",children:"Dialog"})," objects are dispatched by page via the ",(0,l.jsx)(s.a,{href:"/docs/next/api/class-page#page-event-dialog",children:"page.on('dialog')"})," event."]}),"\n",(0,l.jsxs)(s.p,{children:["An example of using ",(0,l.jsx)(s.code,{children:"Dialog"})," class:"]}),"\n",(0,l.jsx)(s.pre,{children:(0,l.jsx)(s.code,{className:"language-js",children:"const { chromium } = require('playwright');  // Or 'firefox' or 'webkit'.\n\n(async () => {\n  const browser = await chromium.launch();\n  const page = await browser.newPage();\n  page.on('dialog', async dialog => {\n    console.log(dialog.message());\n    await dialog.dismiss();\n  });\n  await page.evaluate(() => alert('1'));\n  await browser.close();\n})();\n"})}),"\n",(0,l.jsx)(s.admonition,{type:"note",children:(0,l.jsxs)(s.p,{children:["Dialogs are dismissed automatically, unless there is a ",(0,l.jsx)(s.a,{href:"/docs/next/api/class-page#page-event-dialog",children:"page.on('dialog')"})," listener. When listener is present, it ",(0,l.jsx)(s.strong,{children:"must"})," either ",(0,l.jsx)(s.a,{href:"/docs/next/api/class-dialog#dialog-accept",children:"dialog.accept()"})," or ",(0,l.jsx)(s.a,{href:"/docs/next/api/class-dialog#dialog-dismiss",children:"dialog.dismiss()"})," the dialog - otherwise the page will ",(0,l.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking",children:"freeze"})," waiting for the dialog, and actions like click will never finish."]})}),"\n",(0,l.jsx)(s.hr,{}),"\n",(0,l.jsx)(s.h2,{id:"methods",children:"Methods"}),"\n",(0,l.jsx)(s.h3,{id:"dialog-accept",children:"accept"}),"\n",(0,l.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,l.jsx)("x-search",{children:"dialog.accept"}),"\n",(0,l.jsx)(s.p,{children:"Returns when the dialog has been accepted."}),"\n",(0,l.jsx)(s.p,{children:(0,l.jsx)(s.strong,{children:"Usage"})}),"\n",(0,l.jsx)(s.pre,{children:(0,l.jsx)(s.code,{className:"language-js",children:"await dialog.accept();\nawait dialog.accept(promptText);\n"})}),"\n",(0,l.jsx)(s.p,{children:(0,l.jsx)(s.strong,{children:"Arguments"})}),"\n",(0,l.jsxs)(s.ul,{children:["\n",(0,l.jsxs)(s.li,{children:["\n",(0,l.jsxs)(s.p,{children:[(0,l.jsx)(s.code,{children:"promptText"})," ",(0,l.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})," ",(0,l.jsx)(s.em,{children:"(optional)"}),(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"dialog-accept-option-prompt-text"}),(0,l.jsx)("a",{href:"#dialog-accept-option-prompt-text",class:"list-anchor",children:"#"})]}),"\n",(0,l.jsxs)(s.p,{children:["A text to enter in prompt. Does not cause any effects if the dialog's ",(0,l.jsx)(s.code,{children:"type"})," is not prompt. Optional."]}),"\n"]}),"\n"]}),"\n",(0,l.jsx)(s.p,{children:(0,l.jsx)(s.strong,{children:"Returns"})}),"\n",(0,l.jsxs)(s.ul,{children:["\n",(0,l.jsxs)(s.li,{children:[(0,l.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,l.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined",title:"void",children:"void"}),">",(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"dialog-accept-return"}),(0,l.jsx)("a",{href:"#dialog-accept-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,l.jsx)(s.hr,{}),"\n",(0,l.jsx)(s.h3,{id:"dialog-default-value",children:"defaultValue"}),"\n",(0,l.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,l.jsx)("x-search",{children:"dialog.defaultValue"}),"\n",(0,l.jsx)(s.p,{children:"If dialog is prompt, returns default prompt value. Otherwise, returns empty string."}),"\n",(0,l.jsx)(s.p,{children:(0,l.jsx)(s.strong,{children:"Usage"})}),"\n",(0,l.jsx)(s.pre,{children:(0,l.jsx)(s.code,{className:"language-js",children:"dialog.defaultValue();\n"})}),"\n",(0,l.jsx)(s.p,{children:(0,l.jsx)(s.strong,{children:"Returns"})}),"\n",(0,l.jsxs)(s.ul,{children:["\n",(0,l.jsxs)(s.li,{children:[(0,l.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"dialog-default-value-return"}),(0,l.jsx)("a",{href:"#dialog-default-value-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,l.jsx)(s.hr,{}),"\n",(0,l.jsx)(s.h3,{id:"dialog-dismiss",children:"dismiss"}),"\n",(0,l.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,l.jsx)("x-search",{children:"dialog.dismiss"}),"\n",(0,l.jsx)(s.p,{children:"Returns when the dialog has been dismissed."}),"\n",(0,l.jsx)(s.p,{children:(0,l.jsx)(s.strong,{children:"Usage"})}),"\n",(0,l.jsx)(s.pre,{children:(0,l.jsx)(s.code,{className:"language-js",children:"await dialog.dismiss();\n"})}),"\n",(0,l.jsx)(s.p,{children:(0,l.jsx)(s.strong,{children:"Returns"})}),"\n",(0,l.jsxs)(s.ul,{children:["\n",(0,l.jsxs)(s.li,{children:[(0,l.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,l.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined",title:"void",children:"void"}),">",(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"dialog-dismiss-return"}),(0,l.jsx)("a",{href:"#dialog-dismiss-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,l.jsx)(s.hr,{}),"\n",(0,l.jsx)(s.h3,{id:"dialog-message",children:"message"}),"\n",(0,l.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,l.jsx)("x-search",{children:"dialog.message"}),"\n",(0,l.jsx)(s.p,{children:"A message displayed in the dialog."}),"\n",(0,l.jsx)(s.p,{children:(0,l.jsx)(s.strong,{children:"Usage"})}),"\n",(0,l.jsx)(s.pre,{children:(0,l.jsx)(s.code,{className:"language-js",children:"dialog.message();\n"})}),"\n",(0,l.jsx)(s.p,{children:(0,l.jsx)(s.strong,{children:"Returns"})}),"\n",(0,l.jsxs)(s.ul,{children:["\n",(0,l.jsxs)(s.li,{children:[(0,l.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"dialog-message-return"}),(0,l.jsx)("a",{href:"#dialog-message-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,l.jsx)(s.hr,{}),"\n",(0,l.jsx)(s.h3,{id:"dialog-page",children:"page"}),"\n",(0,l.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.34"}),"\n",(0,l.jsx)("x-search",{children:"dialog.page"}),"\n",(0,l.jsx)(s.p,{children:"The page that initiated this dialog, if available."}),"\n",(0,l.jsx)(s.p,{children:(0,l.jsx)(s.strong,{children:"Usage"})}),"\n",(0,l.jsx)(s.pre,{children:(0,l.jsx)(s.code,{className:"language-js",children:"dialog.page();\n"})}),"\n",(0,l.jsx)(s.p,{children:(0,l.jsx)(s.strong,{children:"Returns"})}),"\n",(0,l.jsxs)(s.ul,{children:["\n",(0,l.jsxs)(s.li,{children:[(0,l.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null",title:"null",children:"null"})," | ",(0,l.jsx)(s.a,{href:"/docs/next/api/class-page",title:"Page",children:"Page"}),(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"dialog-page-return"}),(0,l.jsx)("a",{href:"#dialog-page-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,l.jsx)(s.hr,{}),"\n",(0,l.jsx)(s.h3,{id:"dialog-type",children:"type"}),"\n",(0,l.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,l.jsx)("x-search",{children:"dialog.type"}),"\n",(0,l.jsxs)(s.p,{children:["Returns dialog's type, can be one of ",(0,l.jsx)(s.code,{children:"alert"}),", ",(0,l.jsx)(s.code,{children:"beforeunload"}),", ",(0,l.jsx)(s.code,{children:"confirm"})," or ",(0,l.jsx)(s.code,{children:"prompt"}),"."]}),"\n",(0,l.jsx)(s.p,{children:(0,l.jsx)(s.strong,{children:"Usage"})}),"\n",(0,l.jsx)(s.pre,{children:(0,l.jsx)(s.code,{className:"language-js",children:"dialog.type();\n"})}),"\n",(0,l.jsx)(s.p,{children:(0,l.jsx)(s.strong,{children:"Returns"})}),"\n",(0,l.jsxs)(s.ul,{children:["\n",(0,l.jsxs)(s.li,{children:[(0,l.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),(0,l.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"dialog-type-return"}),(0,l.jsx)("a",{href:"#dialog-type-return",class:"list-anchor",children:"#"})]}),"\n"]})]})}function h(e={}){let{wrapper:s}={...(0,a.R)(),...e.components};return s?(0,l.jsx)(s,{...e,children:(0,l.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.