Class: Playwright::Browser
- Inherits:
-
PlaywrightApi
- Object
- PlaywrightApi
- Playwright::Browser
- Defined in:
- lib/playwright_api/browser.rb
Overview
-
extends: [EventEmitter](nodejs.org/api/events.html#events_class_eventemitter)
A Browser is created via [‘method: BrowserType.launch`]. An example of using a `Browser` to create a [Page]:
“‘js const { firefox } = require(’playwright’); // Or ‘chromium’ or ‘webkit’.
(async () =>
const browser = await firefox.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await browser.close();
)(); “‘
See ‘ChromiumBrowser`, [FirefoxBrowser] and [WebKitBrowser] for browser-specific features. Note that
- ‘method: BrowserType.launch`
-
always returns a specific browser instance, based on the browser being launched.
Direct Known Subclasses
ChannelOwners::ChromiumBrowser, ChannelOwners::FirefoxBrowser, ChannelOwners::WebkitBrowser
Instance Method Summary collapse
- #after_initialize ⇒ Object
-
#close ⇒ Object
In case this browser is obtained using [‘method: BrowserType.launch`], closes the browser and all of its pages (if any were opened).
-
#connected? ⇒ Boolean
Indicates that the browser is connected.
-
#contexts ⇒ Object
Returns an array of all open browser contexts.
-
#new_context(acceptDownloads: nil, bypassCSP: nil, colorScheme: nil, deviceScaleFactor: nil, extraHTTPHeaders: nil, geolocation: nil, hasTouch: nil, httpCredentials: nil, ignoreHTTPSErrors: nil, isMobile: nil, javaScriptEnabled: nil, locale: nil, logger: nil, offline: nil, permissions: nil, proxy: nil, recordHar: nil, recordVideo: nil, storageState: nil, timezoneId: nil, userAgent: nil, videoSize: nil, videosPath: nil, viewport: nil) ⇒ Object
Creates a new browser context.
-
#new_page(acceptDownloads: nil, bypassCSP: nil, colorScheme: nil, deviceScaleFactor: nil, extraHTTPHeaders: nil, geolocation: nil, hasTouch: nil, httpCredentials: nil, ignoreHTTPSErrors: nil, isMobile: nil, javaScriptEnabled: nil, locale: nil, logger: nil, offline: nil, permissions: nil, proxy: nil, recordHar: nil, recordVideo: nil, storageState: nil, timezoneId: nil, userAgent: nil, videoSize: nil, videosPath: nil, viewport: nil) ⇒ Object
Creates a new page in a new browser context.
-
#version ⇒ Object
Returns the browser version.
Methods inherited from PlaywrightApi
Instance Method Details
#after_initialize ⇒ Object
132 133 134 |
# File 'lib/playwright_api/browser.rb', line 132 def after_initialize wrap_channel_owner(@channel_owner.after_initialize) end |
#close ⇒ Object
In case this browser is obtained using [‘method: BrowserType.launch`], closes the browser and all of its pages (if any were opened).
In case this browser is connected to, 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.
29 30 31 |
# File 'lib/playwright_api/browser.rb', line 29 def close wrap_channel_owner(@channel_owner.close) end |
#connected? ⇒ Boolean
Indicates that the browser is connected.
48 49 50 |
# File 'lib/playwright_api/browser.rb', line 48 def connected? wrap_channel_owner(@channel_owner.connected?) end |
#contexts ⇒ Object
Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts.
“‘js const browser = await pw.webkit.launch(); console.log(browser.contexts().length); // prints `0`
const context = await browser.newContext(); console.log(browser.contexts().length); // prints ‘1` “`
43 44 45 |
# File 'lib/playwright_api/browser.rb', line 43 def contexts wrap_channel_owner(@channel_owner.contexts) end |
#new_context(acceptDownloads: nil, bypassCSP: nil, colorScheme: nil, deviceScaleFactor: nil, extraHTTPHeaders: nil, geolocation: nil, hasTouch: nil, httpCredentials: nil, ignoreHTTPSErrors: nil, isMobile: nil, javaScriptEnabled: nil, locale: nil, logger: nil, offline: nil, permissions: nil, proxy: nil, recordHar: nil, recordVideo: nil, storageState: nil, timezoneId: nil, userAgent: nil, videoSize: nil, videosPath: nil, viewport: nil) ⇒ Object
Creates a new browser context. It won’t share cookies/cache with other browser contexts.
“‘js (async () =>
const browser = await playwright.firefox.launch(); // Or 'chromium' or 'webkit'.
// Create a new incognito browser context.
const context = await browser.newContext();
// Create a new page in a pristine context.
const page = await context.newPage();
await page.goto('https://example.com');
)(); “‘
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/playwright_api/browser.rb', line 65 def new_context( acceptDownloads: nil, bypassCSP: nil, colorScheme: nil, deviceScaleFactor: nil, extraHTTPHeaders: nil, geolocation: nil, hasTouch: nil, httpCredentials: nil, ignoreHTTPSErrors: nil, isMobile: nil, javaScriptEnabled: nil, locale: nil, logger: nil, offline: nil, permissions: nil, proxy: nil, recordHar: nil, recordVideo: nil, storageState: nil, timezoneId: nil, userAgent: nil, videoSize: nil, videosPath: nil, viewport: nil) wrap_channel_owner(@channel_owner.new_context(acceptDownloads: acceptDownloads, bypassCSP: bypassCSP, colorScheme: colorScheme, deviceScaleFactor: deviceScaleFactor, extraHTTPHeaders: extraHTTPHeaders, geolocation: geolocation, hasTouch: hasTouch, httpCredentials: httpCredentials, ignoreHTTPSErrors: ignoreHTTPSErrors, isMobile: isMobile, javaScriptEnabled: javaScriptEnabled, locale: locale, logger: logger, offline: offline, permissions: , proxy: proxy, recordHar: recordHar, recordVideo: recordVideo, storageState: storageState, timezoneId: timezoneId, userAgent: userAgent, videoSize: videoSize, videosPath: videosPath, viewport: )) end |
#new_page(acceptDownloads: nil, bypassCSP: nil, colorScheme: nil, deviceScaleFactor: nil, extraHTTPHeaders: nil, geolocation: nil, hasTouch: nil, httpCredentials: nil, ignoreHTTPSErrors: nil, isMobile: nil, javaScriptEnabled: nil, locale: nil, logger: nil, offline: nil, permissions: nil, proxy: nil, recordHar: nil, recordVideo: nil, storageState: nil, timezoneId: nil, userAgent: nil, videoSize: nil, videosPath: nil, viewport: nil) ⇒ Object
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 [‘method: Browser.newContext`] followed by the
- ‘method: BrowserContext.newPage`
-
to control their exact life times.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/playwright_api/browser.rb', line 98 def new_page( acceptDownloads: nil, bypassCSP: nil, colorScheme: nil, deviceScaleFactor: nil, extraHTTPHeaders: nil, geolocation: nil, hasTouch: nil, httpCredentials: nil, ignoreHTTPSErrors: nil, isMobile: nil, javaScriptEnabled: nil, locale: nil, logger: nil, offline: nil, permissions: nil, proxy: nil, recordHar: nil, recordVideo: nil, storageState: nil, timezoneId: nil, userAgent: nil, videoSize: nil, videosPath: nil, viewport: nil) wrap_channel_owner(@channel_owner.new_page(acceptDownloads: acceptDownloads, bypassCSP: bypassCSP, colorScheme: colorScheme, deviceScaleFactor: deviceScaleFactor, extraHTTPHeaders: extraHTTPHeaders, geolocation: geolocation, hasTouch: hasTouch, httpCredentials: httpCredentials, ignoreHTTPSErrors: ignoreHTTPSErrors, isMobile: isMobile, javaScriptEnabled: javaScriptEnabled, locale: locale, logger: logger, offline: offline, permissions: , proxy: proxy, recordHar: recordHar, recordVideo: recordVideo, storageState: storageState, timezoneId: timezoneId, userAgent: userAgent, videoSize: videoSize, videosPath: videosPath, viewport: )) end |
#version ⇒ Object
Returns the browser version.
127 128 129 |
# File 'lib/playwright_api/browser.rb', line 127 def version wrap_channel_owner(@channel_owner.version) end |