From 1d54499a4b629c86760413c1c1c7a3310218a553 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Thu, 7 Jul 2022 09:18:38 +0200 Subject: [PATCH] fix: expose a RemoteObject getter Closes #8639 --- docs/api/puppeteer.jshandle.md | 1 + docs/api/puppeteer.jshandle.remoteobject.md | 19 +++++++++++++++++++ package.json | 2 +- src/common/JSHandle.ts | 7 +++++++ src/puppeteer.ts | 2 ++ test/src/jshandle.spec.ts | 8 ++++++++ 6 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 docs/api/puppeteer.jshandle.remoteobject.md diff --git a/docs/api/puppeteer.jshandle.md b/docs/api/puppeteer.jshandle.md index 3f90dc708927d..c207f2c9b705a 100644 --- a/docs/api/puppeteer.jshandle.md +++ b/docs/api/puppeteer.jshandle.md @@ -45,4 +45,5 @@ JSHandle instances can be used as arguments for [Page.$eval()](./puppeteer.page. | [getProperty(propertyName)](./puppeteer.jshandle.getproperty.md) | | Fetches a single property from the referenced object. | | [getProperty(propertyName)](./puppeteer.jshandle.getproperty_1.md) | | | | [jsonValue()](./puppeteer.jshandle.jsonvalue.md) | | | +| [remoteObject()](./puppeteer.jshandle.remoteobject.md) | | Provides access to \[Protocol.Runtime.RemoteObject\](https://chromedevtools.github.io/devtools-protocol/tot/Runtime/\#type-RemoteObject) backing this JSHandle. | | [toString()](./puppeteer.jshandle.tostring.md) | | Returns a string representation of the JSHandle. | diff --git a/docs/api/puppeteer.jshandle.remoteobject.md b/docs/api/puppeteer.jshandle.remoteobject.md new file mode 100644 index 0000000000000..868762a1609ac --- /dev/null +++ b/docs/api/puppeteer.jshandle.remoteobject.md @@ -0,0 +1,19 @@ +--- +sidebar_label: JSHandle.remoteObject +--- + +# JSHandle.remoteObject() method + +Provides access to \[Protocol.Runtime.RemoteObject\](https://chromedevtools.github.io/devtools-protocol/tot/Runtime/\#type-RemoteObject) backing this JSHandle. + +**Signature:** + +```typescript +class JSHandle { + remoteObject(): Protocol.Runtime.RemoteObject; +} +``` + +**Returns:** + +Protocol.Runtime.RemoteObject diff --git a/package.json b/package.json index 67c84ce8eb96c..f6861ed85d470 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "docs": "run-s build generate:markdown", "debug": "npm run build && mocha --inspect-brk", "commitlint": "commitlint --from=HEAD~1", - "clean": "rimraf lib", + "clean": "rimraf lib && rimraf test/build", "check": "run-p check:*", "check:protocol-revision": "ts-node -s scripts/ensure-correct-devtools-protocol-package", "check:pinned-deps": "ts-node -s scripts/ensure-pinned-deps", diff --git a/src/common/JSHandle.ts b/src/common/JSHandle.ts index 27f267d5f257f..4cdb08c02ba22 100644 --- a/src/common/JSHandle.ts +++ b/src/common/JSHandle.ts @@ -291,6 +291,13 @@ export class JSHandle { } return 'JSHandle:' + valueFromRemoteObject(this.#remoteObject); } + + /** + * Provides access to [Protocol.Runtime.RemoteObject](https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-RemoteObject) backing this JSHandle. + */ + remoteObject(): Protocol.Runtime.RemoteObject { + return this.#remoteObject; + } } /** diff --git a/src/puppeteer.ts b/src/puppeteer.ts index 21a4a2ca79b46..63317cbf7d63a 100644 --- a/src/puppeteer.ts +++ b/src/puppeteer.ts @@ -21,6 +21,8 @@ export * from './common/QueryHandler.js'; export * from './common/DeviceDescriptors.js'; export * from './common/Errors.js'; +export {Protocol} from 'devtools-protocol'; + /** * @public */ diff --git a/test/src/jshandle.spec.ts b/test/src/jshandle.spec.ts index ab8fe3a3921fc..0bbd1c39199b6 100644 --- a/test/src/jshandle.spec.ts +++ b/test/src/jshandle.spec.ts @@ -36,6 +36,14 @@ describe('JSHandle', function () { }); expect(windowHandle).toBeTruthy(); }); + it('should return the RemoteObject', async () => { + const {page} = getTestState(); + + const windowHandle = await page.evaluateHandle(() => { + return window; + }); + expect(windowHandle.remoteObject()).toBeTruthy(); + }); it('should accept object handle as an argument', async () => { const {page} = getTestState();