Skip to content

Commit 6231d50

Browse files
committed
docs(core-concepts): follow up on object handles
1 parent 39b37be commit 6231d50

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

docs/core-concepts.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ the following primitives.
1414
- [Pages and frames](#pages-and-frames)
1515
- [Selectors](#selectors)
1616
- [Auto-waiting](#auto-waiting)
17-
- [Execution contexts](#execution-contexts)
17+
- [Node.js and browser execution contexts](#node-js-and-browser-execution-contexts)
1818
- [Object & element handles](#object--element-handles)
1919

2020
<br/>
@@ -199,8 +199,8 @@ You can pass primitive types, JSON-alike objects and remote object handles recei
199199

200200
## Object & element handles
201201

202-
Playwright has an API to create **node.js references** to DOM elements or objects inside the page. These
203-
references are called "handles" and live in node.js process, whereas the actual objects reside in browser.
202+
Playwright has an API to create Node-side handles to the page DOM elements or any other objects inside the page.
203+
These handles live in the Node.js process, whereas the actual objects reside in browser.
204204

205205
IMAGE PLACEHOLDER
206206

@@ -213,33 +213,34 @@ Playwright's [`ElementHandle`](./api.md#class-elementhandle) extends
213213
[`JSHandle`](./api.md#class-jshandle).
214214

215215
Handles Lifetime:
216-
- Handles can we aquired using page methods [`page.evaluteHandle`](./api.md#pageevaluatehandlepagefunction-arg), [`page.$`](./api.md#pageselector) or [`page.$$`](./api.md#pageselector-1) or
216+
- Handles can we be acquired using the page methods [`page.evaluteHandle`](./api.md#pageevaluatehandlepagefunction-arg), [`page.$`](./api.md#pageselector) or [`page.$$`](./api.md#pageselector-1) or
217217
their frame counterparts [`frame.evaluateHandle`](./api.md#frameevaluatehandlepagefunction-arg), [`frame.$`](./api.md#frameselector) or [`frame.$$`](./api.md#frameselector-1).
218218
- Once created, handles will retain object from [grabage collection](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management)
219219
- Handles will be **automatically disposed** once the page or frame they belong to navigates or closes.
220220
- Handles can be **manually disposed** using [`jsHandle.dispose`](./api.md#jshandledispose) method.
221221

222-
Handles dereferencing can be done with [`jsHandle.evaluate`](./api.md#jshandleevaluatepagefunction-arg) method:
222+
Here is how you can use these handles:
223223

224224
```js
225-
const handle = await page.$('ul');
226-
await handle.evaluate(element => getComputedStyle(element).getPropertyValue('display'));
225+
// The first parameter of the elementHandle.evaluate callback is the element handle points to.
226+
const ulElementHandle = await page.$('ul');
227+
await ulElementHandle.evaluate(ulElement => getComputedStyle(ulElement).getPropertyValue('display'));
227228
```
228229

229230
Alternatively, handles can be passed as arguments to [`page.evaluate`](./api.md#pageevaluatepagefunction-arg) function:
231+
230232
```js
231-
const handle = await page.$('ul');
232-
await page.evaluate(element => getComputedStyle(element).getPropertyValue('display'), handle);
233+
// In the page API, you can pass handle as a parameter.
234+
const ulElementHandle = await page.$('ul');
235+
await page.evaluate(uiElement => getComputedStyle(uiElement).getPropertyValue('display'), uiElement);
233236
```
234237

235-
236238
#### API reference
237-
- [`JSHandle`](./api.md#class-jshandle)
238-
- [`ElementHandle`](./api.md#class-elementhandle)
239+
- [class `JSHandle`](./api.md#class-jshandle)
240+
- [class `ElementHandle`](./api.md#class-elementhandle)
239241
- [`page.evaluteHandle`](./api.md#pageevaluatehandlepagefunction-arg)
240242
- [`page.$`](./api.md#pageselector)
241243
- [`page.$$`](./api.md#pageselector-1)
242244
- [`jsHandle.evaluate`](./api.md#jshandleevaluatepagefunction-arg)
243245

244246
<br/>
245-

0 commit comments

Comments
 (0)