# class:jshandle
### class: JSHandle v0.9.0
JSHandle 表示页面内的 JavaScript 对象。 JSHandles 可以使用 [page.evaluateHandle](%EF%BC%83pageevaluatehandlepagefunction-args) 方法创建。
```
const windowHandle = await page.evaluateHandle(() => window);// ...
```
JSHandle 可防止引用的 JavaScript 对象被垃圾收集,除非是句柄 [disposed](%EF%BC%83jshandledispose)。 当原始框架被导航或父上下文被破坏时,JSHandles 会自动处理。
JSHandle 实例可以使用在 [`page.$eval()`](%EF%BC%83pageevalselector-pagefunction-args),[`page.evaluate()`](%EF%BC%83pageevaluatepagefunction-args) 和 [`page.evaluateHandle`](%EF%BC%83pageevaluatehandlepagefunction-args) 方法。
#### Methods
- [jsHandle.asElement()](#?product=Puppeteer&version=v1.11.0&show=api-jshandleaselement)v0.9.0
- [jsHandle.dispose()](#?product=Puppeteer&version=v1.11.0&show=api-jshandledispose)v0.9.0
- [jsHandle.executionContext()](#?product=Puppeteer&version=v1.11.0&show=api-jshandleexecutioncontext)v0.9.0
- [jsHandle.getProperties()](#?product=Puppeteer&version=v1.11.0&show=api-jshandlegetproperties)v0.9.0
- [jsHandle.getProperty(propertyName)](#?product=Puppeteer&version=v1.11.0&show=api-jshandlegetpropertypropertyname)v0.9.0
- [jsHandle.jsonValue()](#?product=Puppeteer&version=v1.11.0&show=api-jshandlejsonvalue)v0.9.0
### Methods
#### jsHandle.asElement()v0.9.0
- returns: <?[ElementHandle](#?product=Puppeteer&version=v1.11.0&show=api-class-elementhandle "ElementHandle")>
如果对象句柄是 [ElementHandle](#?product=Puppeteer&version=v1.11.0&show=api-class-elementhandle "ElementHandle") 的一个实例,则返回 `null` 或对象句柄本身。
#### jsHandle.dispose()v0.9.0
- returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Promise which resolves when the object handle is successfully disposed.
`jsHandle.dispose` 方法停止引用元素句柄。
#### jsHandle.executionContext()v0.9.0
- returns: [ExecutionContext](#?product=Puppeteer&version=v1.11.0&show=api-class-executioncontext "ExecutionContext")
返回句柄所属的执行上下文。
#### jsHandle.getProperties()v0.9.0
- returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map "Map")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String"), [JSHandle](#?product=Puppeteer&version=v1.11.0&show=api-class-jshandle "JSHandle")>>>
该方法返回一个包含属性名称作为键的映射和属性值的 JSHandle 实例。
```
const handle = await page.evaluateHandle(() => ({window, document}));const properties = await handle.getProperties();const windowHandle = properties.get('window');const documentHandle = properties.get('document');await handle.dispose();
```
#### jsHandle.getProperty(propertyName)v0.9.0
- `propertyName` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> 属性获取
- returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[JSHandle](#?product=Puppeteer&version=v1.11.0&show=api-class-jshandle "JSHandle")>>
从引用的对象中获取单个属性。
#### jsHandle.jsonValue()v0.9.0
- returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>>
返回对象的 JSON 表示。如果对象又一个 [`toJSON`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#toJSON()\_behavior) 函数, 它 **将不会被调用**。
> **注意** 如果引用的对象不可字符串化,该方法将返回一个空的 JSON 对象。 如果对象具有循环引用,它将引发一个错误。
![](images/pptr.png)
puppeteer.js中文网|class:jshandle
puppeteer.js中文文档, puppeteer chrome, puppeteer firefox, puppeteer api 中文文档
puppeteer.js中文网包含了Puppeteer中文文档,最新资讯,应用案例等。Puppeteer 是一个 Node 库,它提供了一个高级 API 来通过 DevTools 协议控制 Chromium 或 Chrome。
- Introduction
- 版本记录
- 概要
- puppeteer-vs-puppeteer-core
- 环境变量
- error-handling
- working-with-chrome-extensions
- class:puppeteer
- class:browserfetcher
- class:browser
- class:page
- class:worker
- class:accessibility
- class:keyboard
- class:mouse
- class:touchscreen
- class:tracing
- class:dialog
- class:consolemessage
- class:frame
- class:executioncontext
- class:jshandle
- class:elementhandle
- class:request
- class:response
- class:securitydetails
- class:target
- class:cdpsession
- class:coverage
- class:timeouterror