Skip to content

Commit

Permalink
chore: remove page.queryObjects API (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Nov 20, 2019
1 parent 35e6d10 commit 48a78b2
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 92 deletions.
43 changes: 0 additions & 43 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
* [page.mainFrame()](#pagemainframe)
* [page.mouse](#pagemouse)
* [page.pdf](#pagepdf)
* [page.queryObjects(prototypeHandle)](#pagequeryobjectsprototypehandle)
* [page.reload([options])](#pagereloadoptions)
* [page.screenshot([options])](#pagescreenshotoptions)
* [page.select(selector, ...values)](#pageselectselector-values)
Expand Down Expand Up @@ -236,7 +235,6 @@
* [executionContext.evaluate(pageFunction[, ...args])](#executioncontextevaluatepagefunction-args)
* [executionContext.evaluateHandle(pageFunction[, ...args])](#executioncontextevaluatehandlepagefunction-args)
* [executionContext.frame()](#executioncontextframe)
* [executionContext.queryObjects(prototypeHandle)](#executioncontextqueryobjectsprototypehandle)
- [class: JSHandle](#class-jshandle)
* [jsHandle.asElement()](#jshandleaselement)
* [jsHandle.dispose()](#jshandledispose)
Expand Down Expand Up @@ -1624,27 +1622,6 @@ Page is guaranteed to have a main frame which persists during navigations.
#### page.pdf
- returns: <[PDF]>

#### page.queryObjects(prototypeHandle)
- `prototypeHandle` <[JSHandle]> A handle to the object prototype.
- returns: <[Promise]<[JSHandle]>> Promise which resolves to a handle to an array of objects with this prototype.

The method iterates the JavaScript heap and finds all the objects with the given prototype.

```js
// Create a Map object
await page.evaluate(() => window.map = new Map());
// Get a handle to the Map object prototype
const mapPrototype = await page.evaluateHandle(() => Map.prototype);
// Query all map instances into an array
const mapInstances = await page.queryObjects(mapPrototype);
// Count amount of map objects in heap
const count = await page.evaluate(maps => maps.length, mapInstances);
await mapInstances.dispose();
await mapPrototype.dispose();
```

Shortcut for [page.mainFrame().executionContext().queryObjects(prototypeHandle)](#executioncontextqueryobjectsprototypehandle).

#### page.reload([options])
- `options` <[Object]> Navigation parameters which might have the following properties:
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
Expand Down Expand Up @@ -3222,26 +3199,6 @@ await resultHandle.dispose();

> **NOTE** Not every execution context is associated with a frame. For example, workers and extensions have execution contexts that are not associated with frames.

#### executionContext.queryObjects(prototypeHandle)
- `prototypeHandle` <[JSHandle]> A handle to the object prototype.
- returns: <[Promise]<[JSHandle]>> A handle to an array of objects with this prototype

The method iterates the JavaScript heap and finds all the objects with the given prototype.

```js
// Create a Map object
await page.evaluate(() => window.map = new Map());
// Get a handle to the Map object prototype
const mapPrototype = await page.evaluateHandle(() => Map.prototype);
// Query all map instances into an array
const mapInstances = await page.queryObjects(mapPrototype);
// Count amount of map objects in heap
const count = await page.evaluate(maps => maps.length, mapInstances);
await mapInstances.dispose();
await mapPrototype.dispose();
```

### class: JSHandle

JSHandle represents an in-page JavaScript object. JSHandles can be created with the [page.evaluateHandle](#pageevaluatehandlepagefunction-args) method.
Expand Down
9 changes: 0 additions & 9 deletions src/chromium/ExecutionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,6 @@ export class ExecutionContext {
}
}

async queryObjects(prototypeHandle: JSHandle): Promise<JSHandle> {
assert(!prototypeHandle._disposed, 'Prototype JSHandle is disposed!');
assert(prototypeHandle._remoteObject.objectId, 'Prototype JSHandle must not be referencing primitive value');
const response = await this._client.send('Runtime.queryObjects', {
prototypeObjectId: prototypeHandle._remoteObject.objectId
});
return createJSHandle(this, response.objects);
}

async _adoptElementHandle(elementHandle: ElementHandle): Promise<ElementHandle> {
assert(elementHandle.executionContext() !== this, 'Cannot adopt handle that already belongs to this execution context');
assert(this._world, 'Cannot adopt handle without DOMWorld');
Expand Down
5 changes: 0 additions & 5 deletions src/chromium/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,6 @@ export class Page extends EventEmitter {
return context.evaluateHandle(pageFunction, ...args);
}

async queryObjects(prototypeHandle: JSHandle): Promise<JSHandle> {
const context = await this.mainFrame().executionContext();
return context.queryObjects(prototypeHandle);
}

async $eval(selector: string, pageFunction: Function | string, ...args: any[]): Promise<(object | undefined)> {
return this.mainFrame().$eval(selector, pageFunction, ...args);
}
Expand Down
35 changes: 0 additions & 35 deletions test/page.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,41 +284,6 @@ module.exports.addTests = function({testRunner, expect, headless, playwright, FF
});
});

describe.skip(FFOX || WEBKIT)('ExecutionContext.queryObjects', function() {
it('should work', async({page, server}) => {
// Instantiate an object
await page.evaluate(() => window.set = new Set(['hello', 'world']));
const prototypeHandle = await page.evaluateHandle(() => Set.prototype);
const objectsHandle = await page.queryObjects(prototypeHandle);
const count = await page.evaluate(objects => objects.length, objectsHandle);
expect(count).toBe(1);
const values = await page.evaluate(objects => Array.from(objects[0].values()), objectsHandle);
expect(values).toEqual(['hello', 'world']);
});
it('should work for non-blank page', async({page, server}) => {
// Instantiate an object
await page.goto(server.EMPTY_PAGE);
await page.evaluate(() => window.set = new Set(['hello', 'world']));
const prototypeHandle = await page.evaluateHandle(() => Set.prototype);
const objectsHandle = await page.queryObjects(prototypeHandle);
const count = await page.evaluate(objects => objects.length, objectsHandle);
expect(count).toBe(1);
});
it('should fail for disposed handles', async({page, server}) => {
const prototypeHandle = await page.evaluateHandle(() => HTMLBodyElement.prototype);
await prototypeHandle.dispose();
let error = null;
await page.queryObjects(prototypeHandle).catch(e => error = e);
expect(error.message).toBe('Prototype JSHandle is disposed!');
});
it('should fail primitive values as prototypes', async({page, server}) => {
const prototypeHandle = await page.evaluateHandle(() => 42);
let error = null;
await page.queryObjects(prototypeHandle).catch(e => error = e);
expect(error.message).toBe('Prototype JSHandle must not be referencing primitive value');
});
});

describe('Page.Events.Console', function() {
it('should work', async({page, server}) => {
let message = null;
Expand Down

0 comments on commit 48a78b2

Please sign in to comment.