mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: remove import cycle in query handlers (#11234)
This commit is contained in:
parent
edec7d53f8
commit
954c75f9a9
@ -131,10 +131,7 @@ module.exports = {
|
||||
},
|
||||
],
|
||||
|
||||
'import/no-cycle': [
|
||||
'error',
|
||||
{maxDepth: Infinity, allowUnsafeDynamicCyclicDependency: true},
|
||||
],
|
||||
'import/no-cycle': ['error', {maxDepth: Infinity}],
|
||||
|
||||
'no-restricted-syntax': [
|
||||
'error',
|
||||
|
@ -32,6 +32,7 @@ import {assert} from '../util/assert.js';
|
||||
import {AsyncIterableUtil} from '../util/AsyncIterableUtil.js';
|
||||
import {throwIfDisposed} from '../util/decorators.js';
|
||||
|
||||
import {_isElementHandle} from './ElementHandleSymbol.js';
|
||||
import type {
|
||||
KeyboardTypeOptions,
|
||||
KeyPressOptions,
|
||||
@ -149,6 +150,11 @@ export interface ElementScreenshotOptions extends ScreenshotOptions {
|
||||
export abstract class ElementHandle<
|
||||
ElementType extends Node = Element,
|
||||
> extends JSHandle<ElementType> {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
declare [_isElementHandle]: boolean;
|
||||
|
||||
/**
|
||||
* A given method will have it's `this` replaced with an isolated version of
|
||||
* `this` when decorated with this decorator.
|
||||
@ -212,6 +218,7 @@ export abstract class ElementHandle<
|
||||
constructor(handle: JSHandle<ElementType>) {
|
||||
super();
|
||||
this.handle = handle;
|
||||
this[_isElementHandle] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
20
packages/puppeteer-core/src/api/ElementHandleSymbol.ts
Normal file
20
packages/puppeteer-core/src/api/ElementHandleSymbol.ts
Normal file
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const _isElementHandle = Symbol('_isElementHandle');
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import type {ElementHandle} from '../api/ElementHandle.js';
|
||||
import {_isElementHandle} from '../api/ElementHandleSymbol.js';
|
||||
import type {Frame} from '../api/Frame.js';
|
||||
import type {WaitForSelectorOptions} from '../api/Page.js';
|
||||
import type PuppeteerUtil from '../injected/injected.js';
|
||||
@ -132,8 +133,7 @@ export class QueryHandler {
|
||||
return context.puppeteerUtil;
|
||||
})
|
||||
);
|
||||
const {ElementHandle} = await import('../api/ElementHandle.js');
|
||||
if (!(result instanceof ElementHandle)) {
|
||||
if (!(_isElementHandle in result)) {
|
||||
return null;
|
||||
}
|
||||
return result.move();
|
||||
@ -151,10 +151,9 @@ export class QueryHandler {
|
||||
selector: string,
|
||||
options: WaitForSelectorOptions
|
||||
): Promise<ElementHandle<Node> | null> {
|
||||
const {ElementHandle} = await import('../api/ElementHandle.js');
|
||||
let frame!: Frame;
|
||||
using element = await (async () => {
|
||||
if (!(elementOrFrame instanceof ElementHandle)) {
|
||||
if (!(_isElementHandle in elementOrFrame)) {
|
||||
frame = elementOrFrame;
|
||||
return;
|
||||
}
|
||||
@ -198,7 +197,7 @@ export class QueryHandler {
|
||||
throw signal.reason;
|
||||
}
|
||||
|
||||
if (!(handle instanceof ElementHandle)) {
|
||||
if (!(_isElementHandle in handle)) {
|
||||
return null;
|
||||
}
|
||||
return await frame.mainRealm().transferHandle(handle);
|
||||
|
Loading…
Reference in New Issue
Block a user