fix: expose a RemoteObject getter (#8642)

Closes #8639
This commit is contained in:
Alex Rudenko 2022-07-07 15:04:28 +02:00 committed by GitHub
parent f82c03682a
commit d0c4291995
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 1 deletions

View File

@ -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.md) | | Fetches a single property from the referenced object. |
| [getProperty(propertyName)](./puppeteer.jshandle.getproperty_1.md) | | | | [getProperty(propertyName)](./puppeteer.jshandle.getproperty_1.md) | | |
| [jsonValue()](./puppeteer.jshandle.jsonvalue.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. | | [toString()](./puppeteer.jshandle.tostring.md) | | Returns a string representation of the JSHandle. |

View File

@ -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

View File

@ -49,7 +49,7 @@
"docs": "run-s build generate:markdown", "docs": "run-s build generate:markdown",
"debug": "npm run build && mocha --inspect-brk", "debug": "npm run build && mocha --inspect-brk",
"commitlint": "commitlint --from=HEAD~1", "commitlint": "commitlint --from=HEAD~1",
"clean": "rimraf lib", "clean": "rimraf lib && rimraf test/build",
"check": "run-p check:*", "check": "run-p check:*",
"check:protocol-revision": "ts-node -s scripts/ensure-correct-devtools-protocol-package", "check:protocol-revision": "ts-node -s scripts/ensure-correct-devtools-protocol-package",
"check:pinned-deps": "ts-node -s scripts/ensure-pinned-deps", "check:pinned-deps": "ts-node -s scripts/ensure-pinned-deps",

View File

@ -291,6 +291,13 @@ export class JSHandle<T = unknown> {
} }
return 'JSHandle:' + valueFromRemoteObject(this.#remoteObject); 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;
}
} }
/** /**

View File

@ -21,6 +21,8 @@ export * from './common/QueryHandler.js';
export * from './common/DeviceDescriptors.js'; export * from './common/DeviceDescriptors.js';
export * from './common/Errors.js'; export * from './common/Errors.js';
export {Protocol} from 'devtools-protocol';
/** /**
* @public * @public
*/ */

View File

@ -36,6 +36,14 @@ describe('JSHandle', function () {
}); });
expect(windowHandle).toBeTruthy(); 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 () => { it('should accept object handle as an argument', async () => {
const {page} = getTestState(); const {page} = getTestState();