PageSourceSearch

https://playwright.dev/assets/js/90f396e5.cdbe4289.js

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

1"use strict";(self.webpackChunkplaywright_dev=self.webpackChunkplaywright_dev||[]).push([["4251"],{23369(e,r,s){s.r(r),s.d(r,{metadata:()=>i,default:()=>d,frontMatter:()=>t,contentTitle:()=>a,toc:()=>o,assets:()=>c});var i=JSON.parse('{"id":"api/class-playwright","title":"Playwright Library","description":"Playwright module provides a method to launch a browser instance. The following is a typical example of using Playwright to drive automation:","source":"@site/versioned_docs/version-stable/api/class-playwright.mdx","sourceDirName":"api","slug":"/api/class-playwright","permalink":"/docs/api/class-playwright","draft":false,"unlisted":false,"tags":[],"version":"stable","frontMatter":{"id":"class-playwright","title":"Playwright Library"},"sidebar":"api","previous":{"title":"Playwright Test","permalink":"/docs/api/class-test"},"next":{"title":"APIRequest","permalink":"/docs/api/class-apirequest"}}'),n=s(74848),l=s(28453);s(13554),s(41647),s(83137);let t={id:"class-playwright",title:"Playwright Library"},a,c={},o=[{value:"Properties",id:"properties",level:2},{value:"chromium",id:"playwright-chromium",level:3},{value:"devices",id:"playwright-devices",level:3},{value:"errors",id:"playwright-errors",level:3},{value:"firefox",id:"playwright-firefox",level:3},{value:"request",id:"playwright-request",level:3},{value:"selectors",id:"playwright-selectors",level:3},{value:"webkit",id:"playwright-webkit",level:3}];function h(e){let r={a:"a",code:"code",h2:"h2",h3:"h3",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,l.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(r.p,{children:"Playwright module provides a method to launch a browser instance. The following is a typical example of using Playwright to drive automation:"}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-js",children:"const { chromium, firefox, webkit } = require('playwright');\n\n(async () => {\n  const browser = await chromium.launch();  // Or 'firefox' or 'webkit'.\n  const page = await browser.newPage();\n  await page.goto('http://example.com');\n  // other actions...\n  await browser.close();\n})();\n"})}),"\n",(0,n.jsx)(r.hr,{}),"\n",(0,n.jsx)(r.h2,{id:"properties",children:"Properties"}),"\n",(0,n.jsx)(r.h3,{id:"playwright-chromium",children:"chromium"}),"\n",(0,n.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,n.jsx)("x-search",{children:"playwright.chromium"}),"\n",(0,n.jsxs)(r.p,{children:["This object can be used to launch or connect to Chromium, returning instances of ",(0,n.jsx)(r.a,{href:"/docs/api/class-browser",title:"Browser",children:"Browser"}),"."]}),"\n",(0,n.jsx)(r.p,{children:(0,n.jsx)(r.strong,{children:"Usage"})}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-js",children:"playwright.chromium\n"})}),"\n",(0,n.jsx)(r.p,{children:(0,n.jsx)(r.strong,{children:"Type"})}),"\n",(0,n.jsxs)(r.ul,{children:["\n",(0,n.jsx)(r.li,{children:(0,n.jsx)(r.a,{href:"/docs/api/class-browsertype",title:"BrowserType",children:"BrowserType"})}),"\n"]}),"\n",(0,n.jsx)(r.hr,{}),"\n",(0,n.jsx)(r.h3,{id:"playwright-devices",children:"devices"}),"\n",(0,n.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,n.jsx)("x-search",{children:"playwright.devices"}),"\n",(0,n.jsxs)(r.p,{children:["Returns a dictionary of devices to be used with ",(0,n.jsx)(r.a,{href:"/docs/api/class-browser#browser-new-context",children:"browser.newContext()"})," or ",(0,n.jsx)(r.a,{href:"/docs/api/class-browser#browser-new-page",children:"browser.newPage()"}),"."]}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-js",children:"const { webkit, devices } = require('playwright');\nconst iPhone = devices['iPhone 6'];\n\n(async () => {\n  const browser = await webkit.launch();\n  const context = await browser.newContext({\n    ...iPhone\n  });\n  const page = await context.newPage();\n  await page.goto('http://example.com');\n  // other actions...\n  await browser.close();\n})();\n"})}),"\n",(0,n.jsx)(r.p,{children:(0,n.jsx)(r.strong,{children:"Usage"})}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-js",children:"playwright.devices\n"})}),"\n",(0,n.jsx)(r.p,{children:(0,n.jsx)(r.strong,{children:"Type"})}),"\n",(0,n.jsxs)(r.ul,{children:["\n",(0,n.jsx)(r.li,{children:(0,n.jsx)(r.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",title:"Object",children:"Object"})}),"\n"]}),"\n",(0,n.jsx)(r.hr,{}),"\n",(0,n.jsx)(r.h3,{id:"playwright-errors",children:"errors"}),"\n",(0,n.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,n.jsx)("x-search",{children:"playwright.errors"}),"\n",(0,n.jsxs)(r.p,{children:["Playwright methods might throw errors if they are unable to fulfill a request. For example, ",(0,n.jsx)(r.a,{href:"/docs/api/class-locator#locator-wait-for",children:"locator.waitFor()"})," might fail if the selector doesn't match any nodes during the given timeframe."]}),"\n",(0,n.jsxs)(r.p,{children:["For certain types of errors Playwright uses specific error classes. These classes are available via ",(0,n.jsx)(r.a,{href:"#playwright-errors",children:(0,n.jsx)(r.code,{children:"playwright.errors"})}),"."]}),"\n",(0,n.jsx)(r.p,{children:"An example of handling a timeout error:"}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-js",children:"try {\n  await page.locator('.foo').waitFor();\n} catch (e) {\n  if (e instanceof playwright.errors.TimeoutError) {\n    // Do something if this is a timeout.\n  }\n}\n"})}),"\n",(0,n.jsx)(r.p,{children:(0,n.jsx)(r.strong,{children:"Usage"})}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-js",children:"playwright.errors\n"})}),"\n",(0,n.jsx)(r.p,{children:(0,n.jsx)(r.strong,{children:"Type"})}),"\n",(0,n.jsxs)(r.ul,{children:["\n",(0,n.jsxs)(r.li,{children:[(0,n.jsx)(r.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",title:"Object",children:"Object"}),"\n",(0,n.jsxs)(r.ul,{children:["\n",(0,n.jsxs)(r.li,{children:["\n",(0,n.jsxs)(r.p,{children:[(0,n.jsx)(r.code,{children:"TimeoutError"})," ",(0,n.jsx)(r.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function",title:"Function",children:"function"})]}),"\n",(0,n.jsxs)(r.p,{children:["A class of ",(0,n.jsx)(r.a,{href:"/docs/api/class-timeouterror",title:"TimeoutError",children:"TimeoutError"}),"."]}),"\n"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,n.jsx)(r.hr,{}),"\n",(0,n.jsx)(r.h3,{id:"playwright-firefox",children:"firefox"}),"\n",(0,n.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,n.jsx)("x-search",{children:"playwright.firefox"}),"\n",(0,n.jsxs)(r.p,{children:["This object can be used to launch or connect to Firefox, returning instances of ",(0,n.jsx)(r.a,{href:"/docs/api/class-browser",title:"Browser",children:"Browser"}),"."]}),"\n",(0,n.jsx)(r.p,{children:(0,n.jsx)(r.strong,{children:"Usage"})}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-js",children:"playwright.firefox\n"})}),"\n",(0,n.jsx)(r.p,{children:(0,n.jsx)(r.strong,{children:"Type"})}),"\n",(0,n.jsxs)(r.ul,{children:["\n",(0,n.jsx)(r.li,{children:(0,n.jsx)(r.a,{href:"/docs/api/class-browsertype",title:"BrowserType",children:"BrowserType"})}),"\n"]}),"\n",(0,n.jsx)(r.hr,{}),"\n",(0,n.jsx)(r.h3,{id:"playwright-request",children:"request"}),"\n",(0,n.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.16"}),"\n",(0,n.jsx)("x-search",{children:"playwright.request"}),"\n",(0,n.jsx)(r.p,{children:"Exposes API that can be used for the Web API testing."}),"\n",(0,n.jsx)(r.p,{children:(0,n.jsx)(r.strong,{children:"Usage"})}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-js",children:"playwright.request\n"})}),"\n",(0,n.jsx)(r.p,{children:(0,n.jsx)(r.strong,{children:"Type"})}),"\n",(0,n.jsxs)(r.ul,{children:["\n",(0,n.jsx)(r.li,{children:(0,n.jsx)(r.a,{href:"/docs/api/class-apirequest",title:"APIRequest",children:"APIRequest"})}),"\n"]}),"\n",(0,n.jsx)(r.hr,{}),"\n",(0,n.jsx)(r.h3,{id:"playwright-selectors",children:"selectors"}),"\n",(0,n.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,n.jsx)("x-search",{children:"playwright.selectors"}),"\n",(0,n.jsxs)(r.p,{children:["Selectors can be used to install custom selector engines. See ",(0,n.jsx)(r.a,{href:"/docs/extensibility",children:"extensibility"})," for more information."]}),"\n",(0,n.jsx)(r.p,{children:(0,n.jsx)(r.strong,{children:"Usage"})}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-js",children:"playwright.selectors\n"})}),"\n",(0,n.jsx)(r.p,{children:(0,n.jsx)(r.strong,{children:"Type"})}),"\n",(0,n.jsxs)(r.ul,{children:["\n",(0,n.jsx)(r.li,{children:(0,n.jsx)(r.a,{href:"/docs/api/class-selectors",title:"Selectors",children:"Selectors"})}),"\n"]}),"\n",(0,n.jsx)(r.hr,{}),"\n",(0,n.jsx)(r.h3,{id:"playwright-webkit",children:"webkit"}),"\n",(0,n.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,n.jsx)("x-search",{children:"playwright.webkit"}),"\n",(0,n.jsxs)(r.p,{children:["This object can be used to launch or connect to WebKit, returning instances of ",(0,n.jsx)(r.a,{href:"/docs/api/class-browser",title:"Browser",children:"Browser"}),"."]}),"\n",(0,n.jsx)(r.p,{children:(0,n.jsx)(r.strong,{children:"Usage"})}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-js",children:"playwright.webkit\n"})}),"\n",(0,n.jsx)(r.p,{children:(0,n.jsx)(r.strong,{children:"Type"})}),"\n",(0,n.jsxs)(r.ul,{children:["\n",(0,n.jsx)(r.li,{children:(0,n.jsx)(r.a,{href:"/docs/api/class-browsertype",title:"BrowserType",children:"BrowserType"})}),"\n"]})]})}function d(e={}){let{wrapper:r}={...(0,l.R)(),...e.components};return r?(0,n.jsx)(r,{...e,children:(0,n.jsx)(h,{...e})}):h(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.