mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: remove obsolete queryAllArray
(#8847)
This commit is contained in:
parent
b49e742e30
commit
498fbf924c
@ -17,13 +17,12 @@
|
||||
import {Protocol} from 'devtools-protocol';
|
||||
import {assert} from '../util/assert.js';
|
||||
import {CDPSession} from './Connection.js';
|
||||
import {ElementHandle} from './ElementHandle.js';
|
||||
import {
|
||||
IsolatedWorld,
|
||||
PageBinding,
|
||||
WaitForSelectorOptions,
|
||||
} from './IsolatedWorld.js';
|
||||
import {ElementHandle} from './ElementHandle.js';
|
||||
import {JSHandle} from './JSHandle.js';
|
||||
import {InternalQueryHandler} from './QueryHandler.js';
|
||||
|
||||
async function queryAXTree(
|
||||
@ -149,18 +148,6 @@ const queryAll = async (
|
||||
);
|
||||
};
|
||||
|
||||
const queryAllArray = async (
|
||||
element: ElementHandle<Node>,
|
||||
selector: string
|
||||
): Promise<JSHandle<Node[]>> => {
|
||||
const elementHandles = await queryAll(element, selector);
|
||||
const exeCtx = element.executionContext();
|
||||
const jsHandle = exeCtx.evaluateHandle((...elements) => {
|
||||
return elements;
|
||||
}, ...elementHandles);
|
||||
return jsHandle;
|
||||
};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
@ -168,5 +155,4 @@ export const ariaHandler: InternalQueryHandler = {
|
||||
queryOne,
|
||||
waitFor,
|
||||
queryAll,
|
||||
queryAllArray,
|
||||
};
|
||||
|
@ -19,7 +19,7 @@ import {
|
||||
} from './JSHandle.js';
|
||||
import {Page, ScreenshotOptions} from './Page.js';
|
||||
import {getQueryHandlerAndSelector} from './QueryHandler.js';
|
||||
import {EvaluateFunc, NodeFor} from './types.js';
|
||||
import {EvaluateFunc, HandleFor, NodeFor} from './types.js';
|
||||
import {KeyInput} from './USKeyboardLayout.js';
|
||||
import {debugError, isString} from './util.js';
|
||||
|
||||
@ -236,13 +236,24 @@ export class ElementHandle<
|
||||
): Promise<Awaited<ReturnType<Func>>> {
|
||||
const {updatedSelector, queryHandler} =
|
||||
getQueryHandlerAndSelector(selector);
|
||||
assert(queryHandler.queryAllArray);
|
||||
const arrayHandle = (await queryHandler.queryAllArray(
|
||||
assert(
|
||||
queryHandler.queryAll,
|
||||
'Cannot handle queries for a multiple element with the given selector'
|
||||
);
|
||||
const handles = (await queryHandler.queryAll(
|
||||
this,
|
||||
updatedSelector
|
||||
)) as JSHandle<Array<NodeFor<Selector>>>;
|
||||
const result = await arrayHandle.evaluate(pageFunction, ...args);
|
||||
await arrayHandle.dispose();
|
||||
)) as Array<HandleFor<NodeFor<Selector>>>;
|
||||
const elements = await this.evaluateHandle((_, ...elements) => {
|
||||
return elements;
|
||||
}, ...handles);
|
||||
const [result] = await Promise.all([
|
||||
elements.evaluate(pageFunction, ...args),
|
||||
...handles.map(handle => {
|
||||
return handle.dispose();
|
||||
}),
|
||||
]);
|
||||
await elements.dispose();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -15,9 +15,8 @@
|
||||
*/
|
||||
|
||||
import {ariaHandler} from './AriaQueryHandler.js';
|
||||
import {IsolatedWorld, WaitForSelectorOptions} from './IsolatedWorld.js';
|
||||
import {ElementHandle} from './ElementHandle.js';
|
||||
import {JSHandle} from './JSHandle.js';
|
||||
import {IsolatedWorld, WaitForSelectorOptions} from './IsolatedWorld.js';
|
||||
|
||||
/**
|
||||
* @public
|
||||
@ -55,16 +54,6 @@ export interface InternalQueryHandler {
|
||||
element: ElementHandle<Node>,
|
||||
selector: string
|
||||
) => Promise<Array<ElementHandle<Node>>>;
|
||||
/**
|
||||
* Queries for multiple nodes given a selector and {@link ElementHandle}.
|
||||
* Unlike {@link queryAll}, this returns a handle to a node array.
|
||||
*
|
||||
* Akin to {@link Window.prototype.querySelectorAll}.
|
||||
*/
|
||||
queryAllArray?: (
|
||||
element: ElementHandle<Node>,
|
||||
selector: string
|
||||
) => Promise<JSHandle<Node[]>>;
|
||||
|
||||
/**
|
||||
* Waits until a single node appears for a given selector and
|
||||
@ -119,16 +108,6 @@ function internalizeCustomQueryHandler(
|
||||
}
|
||||
return result;
|
||||
};
|
||||
internalHandler.queryAllArray = async (element, selector) => {
|
||||
const resultHandle = (await element.evaluateHandle(
|
||||
queryAll,
|
||||
selector
|
||||
)) as JSHandle<Element[] | NodeListOf<Element>>;
|
||||
const arrayHandle = await resultHandle.evaluateHandle(res => {
|
||||
return Array.from(res);
|
||||
});
|
||||
return arrayHandle;
|
||||
};
|
||||
}
|
||||
|
||||
return internalHandler;
|
||||
|
Loading…
Reference in New Issue
Block a user