- langs: python
Terminates this instance of Playwright in case it was created bypassing the Python context manager. This is useful in REPL applications.
>>> from playwright.sync_api import sync_playwright
>>> playwright = sync_playwright().start()
>>> browser = playwright.chromium.launch()
>>> page = browser.new_page()
>>> page.goto("http://whatsmyuseragent.org/")
>>> page.screenshot(path="example.png")
>>> browser.close()
>>> playwright.stop()
- langs: python
path
<[path]>
Path to the JavaScript file. If path
is a relative path, then it is resolved relative to the current working directory. Optional.
- langs: python
script
<[string]>
Script to be evaluated in all pages in the browser context. Optional.
- langs: python
path
<[path]>
Path to the JavaScript file. If path
is a relative path, then it is resolved relative to the current working directory. Optional.
- langs: python
script
<[string]>
Script to be evaluated in all pages in the browser context. Optional.
- langs: python
name
<[string]>
Frame name specified in the iframe
's name
attribute. Optional.
- langs: python
url
<[string]|[RegExp]|[function]([URL]):[boolean]>
A glob pattern, regex pattern or predicate receiving frame's url
as a [URL] object. Optional.
- langs: python
path
<[path]>
Path to the JavaScript file. If path
is a relative path, then it is resolved relative to the current working directory.
- langs: python
script
<[string]>
Raw script content.
- langs: python
- returns: <[null]|[string]>
- langs: python
- returns: <[EventContextManager]>
- langs: python
- returns: <[EventContextManager]>
- langs: python
- returns: <[EventContextManager]>
- langs: python
- returns: <[EventContextManager]<[Download]>>
Performs action and waits for download
event to fire. If predicate is provided, it passes
[Download] value into the predicate
function and waits for predicate(event)
to return a truthy value.
Will throw an error if the page is closed before the download event is fired.
- langs: python
predicate
<[function]([Download]):[bool]>
Receives the [Download] object and resolves to truthy value when the waiting should resolve.
- langs: python
- returns: <[EventContextManager]<[Page]>>
Performs action and waits for popup
event to fire. If predicate is provided, it passes
[Popup] value into the predicate
function and waits for predicate(event)
to return a truthy value.
Will throw an error if the page is closed before the popup event is fired.
- langs: python
predicate
<[function]([Page]):[bool]>
Receives the [Popup] object and resolves to truthy value when the waiting should resolve.
- langs: python
- returns: <[EventContextManager]<[Worker]>>
Performs action and waits for worker
event to fire. If predicate is provided, it passes
[Worker] value into the predicate
function and waits for predicate(event)
to return a truthy value.
Will throw an error if the page is closed before the worker event is fired.
- langs: python
predicate
<[function]([Worker]):[bool]>
Receives the [Worker] object and resolves to truthy value when the waiting should resolve.
- langs: python
- returns: <[EventContextManager]<[ConsoleMessage]>>
Performs action and waits for console
event to fire. If predicate is provided, it passes
[ConsoleMessage] value into the predicate
function and waits for predicate(event)
to return a truthy value.
Will throw an error if the page is closed before the worker event is fired.
- langs: python
predicate
<[function]([ConsoleMessage]):[bool]>
Receives the [ConsoleMessage] object and resolves to truthy value when the waiting should resolve.
- langs: python
- returns: <[EventContextManager]<[FileChooser]>>
Performs action and waits for filechooser
event to fire. If predicate is provided, it passes
[FileChooser] value into the predicate
function and waits for predicate(event)
to return a truthy value.
Will throw an error if the page is closed before the worker event is fired.
- langs: python
predicate
<[function]([FileChooser]):[bool]>
Receives the [FileChooser] object and resolves to truthy value when the waiting should resolve.
- langs: python
- returns: <[EventContextManager]<[Page]>>
Performs action and waits for page
event to fire. If predicate is provided, it passes
[Page] value into the predicate
function and waits for predicate(event)
to return a truthy value.
Will throw an error if the page is closed before the worker event is fired.
- langs: python
predicate
<[function]([Page]):[bool]>
Receives the [Page] object and resolves to truthy value when the waiting should resolve.
- langs: python
- returns: <[EventContextManager]<[Response]>>
- langs: python
- returns: <[EventContextManager]<[Response]>>
- langs: python
- returns: <[EventContextManager]<[Request]>>
- langs: python
- returns: <[EventContextManager]<[Response]>>
- langs: python
- alias-python: wait_for_event
- returns: <[Any]>
:::note
In most cases, you should use [method: BrowserContext.waitForEvent
].
:::
Waits for given event
to fire. If predicate is provided, it passes
event's value into the predicate
function and waits for predicate(event)
to return a truthy value.
Will throw an error if the socket is closed before the event
is fired.
- langs: python
- alias-python: wait_for_event
- returns: <[Any]>
:::note
In most cases, you should use [method: Page.waitForEvent
].
:::
Waits for given event
to fire. If predicate is provided, it passes
event's value into the predicate
function and waits for predicate(event)
to return a truthy value.
Will throw an error if the socket is closed before the event
is fired.
- langs: python
- alias-python: wait_for_event
- returns: <[Any]>
:::note
In most cases, you should use [method: WebSocket.waitForEvent
].
:::
Waits for given event
to fire. If predicate is provided, it passes
event's value into the predicate
function and waits for predicate(event)
to return a truthy value.
Will throw an error if the socket is closed before the event
is fired.