Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(getProperties): return empty map for non-objects (#470)

Dmitry Gozman88a11a3fbd91
diff --git a/src/firefox/ffExecutionContext.ts b/src/firefox/ffExecutionContext.ts
index 44ec084beb..7821fc91ca 100644
--- a/src/firefox/ffExecutionContext.ts
+++ b/src/firefox/ffExecutionContext.ts
@@ -113,9 +113,12 @@ export class FFExecutionContext implements js.ExecutionContextDelegate {
}
async getProperties(handle: js.JSHandle): Promise<Map<string, js.JSHandle>> {
+ const objectId = handle._remoteObject.objectId;
+ if (!objectId)
+ return new Map();
const response = await this._session.send('Runtime.getObjectProperties', {
executionContextId: this._executionContextId,
- objectId: handle._remoteObject.objectId,
+ objectId,
});
const result = new Map();
for (const property of response.properties)
diff --git a/test/jshandle.spec.js b/test/jshandle.spec.js
index 0dcd0d61cc..710967d177 100644
--- a/test/jshandle.spec.js
+++ b/test/jshandle.spec.js
@@ -115,6 +115,11 @@ module.exports.describe = function({testRunner, expect, CHROMIUM, FFOX, WEBKIT})
expect(foo).toBeTruthy();
expect(await foo.jsonValue()).toBe('bar');
});
+ it('should return empty map for non-objects', async({page, server}) => {
+ const aHandle = await page.evaluateHandle(() => 123);
+ const properties = await aHandle.getProperties();
+ expect(properties.size).toBe(0);
+ });
it('should return even non-own properties', async({page, server}) => {
const aHandle = await page.evaluateHandle(() => {
class A {