@@ -14,6 +14,37 @@ const { firefox } = require('playwright'); // Or 'chromium' or 'webkit'.
14
14
})();
15
15
```
16
16
17
+ ``` python async
18
+ import asyncio
19
+ from playwright.async_api import async_playwright
20
+
21
+ async def run (playwright ):
22
+ firefox = playwright.firefox
23
+ browser = await firefox.launch()
24
+ page = await browser.new_page()
25
+ await page.goto(" https://example.com" )
26
+ await browser.close()
27
+
28
+ async def main ():
29
+ async with async_playwright() as playwright:
30
+ await run(playwright)
31
+ asyncio.run(main())
32
+ ```
33
+
34
+ ``` python sync
35
+ from playwright.sync_api import sync_playwright
36
+
37
+ def run (playwright ):
38
+ firefox = playwright.firefox
39
+ browser = firefox.launch()
40
+ page = browser.new_page()
41
+ page.goto(" https://example.com" )
42
+ browser.close()
43
+
44
+ with sync_playwright() as playwright:
45
+ run(playwright)
46
+ ```
47
+
17
48
## event: Browser.disconnected
18
49
19
50
Emitted when Browser gets disconnected from the browser application. This might happen because of one of the following:
@@ -25,8 +56,8 @@ Emitted when Browser gets disconnected from the browser application. This might
25
56
In case this browser is obtained using [ ` method: BrowserType.launch ` ] , closes the browser and all of its pages (if any
26
57
were opened).
27
58
28
- In case this browser is connected to, clears all created contexts belonging to this
29
- browser and disconnects from the browser server.
59
+ In case this browser is connected to, clears all created contexts belonging to this browser and disconnects from the
60
+ browser server.
30
61
31
62
The [ Browser] object itself is considered to be disposed and cannot be used anymore.
32
63
@@ -43,6 +74,20 @@ const context = await browser.newContext();
43
74
console .log (browser .contexts ().length ); // prints `1`
44
75
```
45
76
77
+ ``` python async
78
+ browser = await pw.webkit.launch()
79
+ print (len (browser.contexts())) # prints `0`
80
+ context = await browser.new_context()
81
+ print (len (browser.contexts())) # prints `1`
82
+ ```
83
+
84
+ ``` python sync
85
+ browser = pw.webkit.launch()
86
+ print (len (browser.contexts())) # prints `0`
87
+ context = browser.new_context()
88
+ print (len (browser.contexts())) # prints `1`
89
+ ```
90
+
46
91
## method: Browser.isConnected
47
92
- returns: <[ boolean] >
48
93
@@ -64,6 +109,24 @@ Creates a new browser context. It won't share cookies/cache with other browser c
64
109
})();
65
110
```
66
111
112
+ ``` python async
113
+ browser = await playwright.firefox.launch() # or "chromium" or "webkit".
114
+ # create a new incognito browser context.
115
+ context = await browser.new_context()
116
+ # create a new page in a pristine context.
117
+ page = await context.new_page()
118
+ await page.goto(" https://example.com" )
119
+ ```
120
+
121
+ ``` python sync
122
+ browser = playwright.firefox.launch() # or "chromium" or "webkit".
123
+ # create a new incognito browser context.
124
+ context = browser.new_context()
125
+ # create a new page in a pristine context.
126
+ page = context.new_page()
127
+ page.goto(" https://example.com" )
128
+ ```
129
+
67
130
### option: Browser.newContext.-inline- = %%-shared-context-params-list-%%
68
131
69
132
### option: Browser.newContext.proxy = %%-context-option-proxy-%%
@@ -76,8 +139,8 @@ Creates a new browser context. It won't share cookies/cache with other browser c
76
139
Creates a new page in a new browser context. Closing this page will close the context as well.
77
140
78
141
This is a convenience API that should only be used for the single-page scenarios and short snippets. Production code and
79
- testing frameworks should explicitly create [ ` method: Browser.newContext ` ] followed by the [ `method:
80
- BrowserContext.newPage`] to control their exact life times.
142
+ testing frameworks should explicitly create [ ` method: Browser.newContext ` ] followed by the
143
+ [ ` method: BrowserContext.newPage` ] to control their exact life times.
81
144
82
145
### option: Browser.newPage.-inline- = %%-shared-context-params-list-%%
83
146
0 commit comments