From 525f13cd18b39cc951a84aa51b2d852758e6f0d2 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Mon, 23 Oct 2023 11:20:04 +0200 Subject: [PATCH] fix: remove import cycle (#11227) --- .../src/cdp/ExecutionContext.ts | 20 ----------------- packages/puppeteer-core/src/cdp/JSHandle.ts | 22 +++++++++++++++++-- packages/puppeteer-core/src/cdp/Page.ts | 3 ++- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/packages/puppeteer-core/src/cdp/ExecutionContext.ts b/packages/puppeteer-core/src/cdp/ExecutionContext.ts index 67c73a74..f4d9eb87 100644 --- a/packages/puppeteer-core/src/cdp/ExecutionContext.ts +++ b/packages/puppeteer-core/src/cdp/ExecutionContext.ts @@ -26,7 +26,6 @@ import { PuppeteerURL, SOURCE_URL_REGEX, createEvaluationError, - debugError, getSourcePuppeteerURLIfAvailable, getSourceUrlComment, isString, @@ -400,22 +399,3 @@ export function createCdpHandle( } return new CdpJSHandle(realm, remoteObject); } - -/** - * @internal - */ -export async function releaseObject( - client: CDPSession, - remoteObject: Protocol.Runtime.RemoteObject -): Promise { - if (!remoteObject.objectId) { - return; - } - await client - .send('Runtime.releaseObject', {objectId: remoteObject.objectId}) - .catch(error => { - // Exceptions might happen in case of a page been navigated or closed. - // Swallow these since they are harmless and we don't leak anything in this case. - debugError(error); - }); -} diff --git a/packages/puppeteer-core/src/cdp/JSHandle.ts b/packages/puppeteer-core/src/cdp/JSHandle.ts index 21cb3cea..f1db31d3 100644 --- a/packages/puppeteer-core/src/cdp/JSHandle.ts +++ b/packages/puppeteer-core/src/cdp/JSHandle.ts @@ -18,10 +18,9 @@ import type {Protocol} from 'devtools-protocol'; import type {CDPSession} from '../api/CDPSession.js'; import {JSHandle} from '../api/JSHandle.js'; -import {valueFromRemoteObject} from '../common/util.js'; +import {debugError, valueFromRemoteObject} from '../common/util.js'; import type {CdpElementHandle} from './ElementHandle.js'; -import {releaseObject} from './ExecutionContext.js'; import type {IsolatedWorld} from './IsolatedWorld.js'; /** @@ -98,3 +97,22 @@ export class CdpJSHandle extends JSHandle { return this.#remoteObject; } } + +/** + * @internal + */ +export async function releaseObject( + client: CDPSession, + remoteObject: Protocol.Runtime.RemoteObject +): Promise { + if (!remoteObject.objectId) { + return; + } + await client + .send('Runtime.releaseObject', {objectId: remoteObject.objectId}) + .catch(error => { + // Exceptions might happen in case of a page been navigated or closed. + // Swallow these since they are harmless and we don't leak anything in this case. + debugError(error); + }); +} diff --git a/packages/puppeteer-core/src/cdp/Page.ts b/packages/puppeteer-core/src/cdp/Page.ts index 17197caf..75f6ce74 100644 --- a/packages/puppeteer-core/src/cdp/Page.ts +++ b/packages/puppeteer-core/src/cdp/Page.ts @@ -73,12 +73,13 @@ import {Coverage} from './Coverage.js'; import type {DeviceRequestPrompt} from './DeviceRequestPrompt.js'; import {CdpDialog} from './Dialog.js'; import {EmulationManager} from './EmulationManager.js'; -import {createCdpHandle, releaseObject} from './ExecutionContext.js'; +import {createCdpHandle} from './ExecutionContext.js'; import {FirefoxTargetManager} from './FirefoxTargetManager.js'; import type {CdpFrame} from './Frame.js'; import {FrameManager, FrameManagerEvent} from './FrameManager.js'; import {CdpKeyboard, CdpMouse, CdpTouchscreen} from './Input.js'; import {MAIN_WORLD} from './IsolatedWorlds.js'; +import {releaseObject} from './JSHandle.js'; import type {Credentials, NetworkConditions} from './NetworkManager.js'; import type {CdpTarget} from './Target.js'; import type {TargetManager} from './TargetManager.js';