Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: expose RemoteObject and Protocol #8642

Merged
merged 1 commit into from Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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