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 {Protocol} from 'devtools-protocol';
|
||||||
import {assert} from '../util/assert.js';
|
import {assert} from '../util/assert.js';
|
||||||
import {CDPSession} from './Connection.js';
|
import {CDPSession} from './Connection.js';
|
||||||
|
import {ElementHandle} from './ElementHandle.js';
|
||||||
import {
|
import {
|
||||||
IsolatedWorld,
|
IsolatedWorld,
|
||||||
PageBinding,
|
PageBinding,
|
||||||
WaitForSelectorOptions,
|
WaitForSelectorOptions,
|
||||||
} from './IsolatedWorld.js';
|
} from './IsolatedWorld.js';
|
||||||
import {ElementHandle} from './ElementHandle.js';
|
|
||||||
import {JSHandle} from './JSHandle.js';
|
|
||||||
import {InternalQueryHandler} from './QueryHandler.js';
|
import {InternalQueryHandler} from './QueryHandler.js';
|
||||||
|
|
||||||
async function queryAXTree(
|
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
|
* @internal
|
||||||
*/
|
*/
|
||||||
@ -168,5 +155,4 @@ export const ariaHandler: InternalQueryHandler = {
|
|||||||
queryOne,
|
queryOne,
|
||||||
waitFor,
|
waitFor,
|
||||||
queryAll,
|
queryAll,
|
||||||
queryAllArray,
|
|
||||||
};
|
};
|
||||||
|
@ -19,7 +19,7 @@ import {
|
|||||||
} from './JSHandle.js';
|
} from './JSHandle.js';
|
||||||
import {Page, ScreenshotOptions} from './Page.js';
|
import {Page, ScreenshotOptions} from './Page.js';
|
||||||
import {getQueryHandlerAndSelector} from './QueryHandler.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 {KeyInput} from './USKeyboardLayout.js';
|
||||||
import {debugError, isString} from './util.js';
|
import {debugError, isString} from './util.js';
|
||||||
|
|
||||||
@ -236,13 +236,24 @@ export class ElementHandle<
|
|||||||
): Promise<Awaited<ReturnType<Func>>> {
|
): Promise<Awaited<ReturnType<Func>>> {
|
||||||
const {updatedSelector, queryHandler} =
|
const {updatedSelector, queryHandler} =
|
||||||
getQueryHandlerAndSelector(selector);
|
getQueryHandlerAndSelector(selector);
|
||||||
assert(queryHandler.queryAllArray);
|
assert(
|
||||||
const arrayHandle = (await queryHandler.queryAllArray(
|
queryHandler.queryAll,
|
||||||
|
'Cannot handle queries for a multiple element with the given selector'
|
||||||
|
);
|
||||||
|
const handles = (await queryHandler.queryAll(
|
||||||
this,
|
this,
|
||||||
updatedSelector
|
updatedSelector
|
||||||
)) as JSHandle<Array<NodeFor<Selector>>>;
|
)) as Array<HandleFor<NodeFor<Selector>>>;
|
||||||
const result = await arrayHandle.evaluate(pageFunction, ...args);
|
const elements = await this.evaluateHandle((_, ...elements) => {
|
||||||
await arrayHandle.dispose();
|
return elements;
|
||||||
|
}, ...handles);
|
||||||
|
const [result] = await Promise.all([
|
||||||
|
elements.evaluate(pageFunction, ...args),
|
||||||
|
...handles.map(handle => {
|
||||||
|
return handle.dispose();
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
await elements.dispose();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,9 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {ariaHandler} from './AriaQueryHandler.js';
|
import {ariaHandler} from './AriaQueryHandler.js';
|
||||||
import {IsolatedWorld, WaitForSelectorOptions} from './IsolatedWorld.js';
|
|
||||||
import {ElementHandle} from './ElementHandle.js';
|
import {ElementHandle} from './ElementHandle.js';
|
||||||
import {JSHandle} from './JSHandle.js';
|
import {IsolatedWorld, WaitForSelectorOptions} from './IsolatedWorld.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
@ -55,16 +54,6 @@ export interface InternalQueryHandler {
|
|||||||
element: ElementHandle<Node>,
|
element: ElementHandle<Node>,
|
||||||
selector: string
|
selector: string
|
||||||
) => Promise<Array<ElementHandle<Node>>>;
|
) => 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
|
* Waits until a single node appears for a given selector and
|
||||||
@ -119,16 +108,6 @@ function internalizeCustomQueryHandler(
|
|||||||
}
|
}
|
||||||
return result;
|
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;
|
return internalHandler;
|
||||||
|
Loading…
Reference in New Issue
Block a user