You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[TypeScript IDE support](#typescript-ide-support)
9
10
<!-- GEN:stop -->
10
11
11
-
<br>
12
-
13
12
## Installation
14
13
15
-
Use npm or Yarn to install Playwright in your Node.js project. Playwright requires Node.js 10 or higher.
14
+
Use npm or Yarn to install Playwright in your Node.js project. See [system requirements](#system-requirements).
16
15
17
16
```sh
18
17
npm i -D playwright
19
18
```
20
19
21
-
During installation, Playwright downloads browser binaries for Chromium, Firefox and WebKit. This sets up your environment for browser automation with just one command. It is possible to modify this default behavior for monorepos and other scenarios. See [installation parameters](installation.md) for mode details.
22
-
23
-
<br>
20
+
This single command downloads the Playwright NPM package and browser binaries for Chromium, Firefox and WebKit. To modify this behavior see [installation parameters](installation.md).
Playwright APIs are asynchronous and return Promise objects. Our code examples use [the async/await pattern](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await) to simplify comprehension. The code is wrapped in an unnamed async arrow function which is invoking itself.
36
+
Playwright APIs are asynchronous and return Promise objects. Our code examples use [the async/await pattern](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await) to ease readability. The code is wrapped in an unnamed async arrow function which is invoking itself.
40
37
41
38
```js
42
39
(async () => { // Start of async arrow function
@@ -45,8 +42,6 @@ Playwright APIs are asynchronous and return Promise objects. Our code examples u
45
42
})(); // End of the function and () to invoke itself
46
43
```
47
44
48
-
<br>
49
-
50
45
## First script
51
46
52
47
In our first script, we will navigate to `whatsmyuseragent.org` and take a screenshot in WebKit.
@@ -69,43 +64,49 @@ By default, Playwright runs the browsers in headless mode. To see the browser UI
69
64
firefox.launch({ headless:false, slowMo:50 });
70
65
```
71
66
72
-
<br>
73
-
74
-
## System requirements
67
+
## Record scripts
75
68
76
-
Playwright requires Node.js version 10.15 or above. The browser binaries for Chromium,
77
-
Firefox and WebKit work across the 3 platforms (Windows, macOS, Linux):
69
+
[Playwright CLI](https://www.npmjs.com/package/playwright-cli) can be used to record user interactions and generate JavaScript code.
78
70
79
-
***Windows**: Works with Windows and Windows Subsystem for Linux (WSL).
80
-
***macOS**: Requires 10.14 or above.
81
-
***Linux**: Depending on your Linux distribution, you might need to install additional
82
-
dependencies to run the browsers.
83
-
* Firefox requires Ubuntu 18.04+
84
-
* For Ubuntu 18.04, the additional dependencies are defined in [our Docker image](docker/Dockerfile.bionic),
85
-
which is based on Ubuntu.
86
-
87
-
<br>
88
-
89
-
## TypeScript IDE support
90
-
91
-
Playwright comes with built-in support for TypeScript. Playwright type definitions will be imported automatically.
71
+
```
72
+
npx playwright-cli codegen wikipedia.org
73
+
```
92
74
93
-
It is also possible to add these types to your variables manually. In TypeScript:
75
+
## TypeScript support
94
76
95
-
```ts
96
-
let page:import('playwright').Page;
97
-
```
77
+
Playwright includes built-in support for TypeScript. Type definitions will be imported automatically. It is recommended to use type-checking to improve the IDE experience.
98
78
99
-
If you use JavaScript, you can still use TypeScript definitions for improved auto-completions and warnings in Visual Studio Code or WebStorm. Add the following to the top of your JavaScript file:
79
+
### In JavaScript
80
+
Add the following to the top of your JavaScript file to get type-checking in VS Code or WebStorm.
100
81
101
82
```js
102
83
//@ts-check
103
84
// ...
104
85
```
105
86
106
-
You can also use JSDoc to set types for variables.
87
+
Alternatively, you can use JSDoc to set types for variables.
107
88
108
89
```js
109
90
/**@type{import('playwright').Page}*/
110
91
let page;
111
92
```
93
+
94
+
### In TypeScript
95
+
TypeScript support will work out-of-the-box. Types can also be imported explicitly.
96
+
97
+
```ts
98
+
let page:import('playwright').Page;
99
+
```
100
+
101
+
## System requirements
102
+
103
+
Playwright requires Node.js version 10.17 or above. The browser binaries for Chromium,
104
+
Firefox and WebKit work across the 3 platforms (Windows, macOS, Linux):
105
+
106
+
***Windows**: Works with Windows and Windows Subsystem for Linux (WSL).
107
+
***macOS**: Requires 10.14 or above.
108
+
***Linux**: Depending on your Linux distribution, you might need to install additional
109
+
dependencies to run the browsers.
110
+
* Firefox requires Ubuntu 18.04+
111
+
* For Ubuntu 18.04, the additional dependencies are defined in [our Docker image](docker/Dockerfile.bionic),
0 commit comments