Skip to content

Commit

Permalink
fix: expose a RemoteObject getter
Browse files Browse the repository at this point in the history
Closes #8639
  • Loading branch information
OrKoN committed Jul 7, 2022
1 parent f82c036 commit 1d54499
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/api/puppeteer.jshandle.md
Expand Up @@ -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. |
19 changes: 19 additions & 0 deletions 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
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions src/common/JSHandle.ts
Expand Up @@ -291,6 +291,13 @@ export class JSHandle<T = unknown> {
}
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;
}
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/puppeteer.ts
Expand Up @@ -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
*/
Expand Down
8 changes: 8 additions & 0 deletions test/src/jshandle.spec.ts
Expand Up @@ -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();

Expand Down

0 comments on commit 1d54499

Please sign in to comment.