module Playwright::Browser
Overview
A Browser is created when Playwright connects to a browser instance, either through browserType.launch([options])
or browserType.connect(params)
.
An example of using a Browser to create a Page:
See ChromiumBrowser, FirefoxBrowser and WebKitBrowser for browser-specific features. Note that browserType.connect(params)
and browserType.launch([options])
always return a specific browser instance, based on the browser being connected to or launched.
Defined in:
playwright/browser.crInstance Method Summary
- #add_listener(type : EventType, listener : Listener(EventType))
-
#close : Nil
In case this browser is obtained using
browserType.launch([options])
, closes the browser and all of its pages (if any were opened). -
#contexts : Array(BrowserContext)
Returns an array of all open browser contexts.
-
#is_connected : Bool
Indicates that the browser is connected.
-
#new_context(options : NewContextOptions | Nil) : BrowserContext
Creates a new browser context.
- #new_context : BrowserContext
-
#new_page(options : NewPageOptions | Nil) : Page
Creates a new page in a new browser context.
- #new_page : Page
- #remove_listener(type : EventType, listener : Listener(EventType))
-
#version : String
Returns the browser version.
Instance Method Detail
In case this browser is obtained using browserType.launch([options])
, closes the browser and all of its pages (if any were opened).
In case this browser is obtained using browserType.connect(params)
, clears all created contexts belonging to this browser and disconnects from the browser server.
The Browser object itself is considered to be disposed and cannot be used anymore.
Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts.
Creates a new browser context. It won't share cookies/cache with other browser contexts.
Creates a new page in a new browser context. Closing this page will close the context as well.
This is a convenience API that should only be used for the single-page scenarios and short snippets. Production code and testing frameworks should explicitly create browser.newContext([options])
followed by the browserContext.newPage()
to control their exact life times.