chore(bidi): do not leak utility handles (#34892)

This commit is contained in:
Yury Semikhatsky 2025-02-21 17:44:33 -08:00 committed by GitHub
parent 962a752832
commit 1af59ee523
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -140,7 +140,7 @@ export class BidiExecutionContext implements js.ExecutionContextDelegate {
} }
async remoteObjectForNodeId(context: dom.FrameExecutionContext, nodeId: bidi.Script.SharedReference): Promise<js.JSHandle> { async remoteObjectForNodeId(context: dom.FrameExecutionContext, nodeId: bidi.Script.SharedReference): Promise<js.JSHandle> {
const result = await this._remoteValueForReference(nodeId); const result = await this._remoteValueForReference(nodeId, true);
if (!('handle' in result)) if (!('handle' in result))
throw new Error('Can\'t get remote object for nodeId'); throw new Error('Can\'t get remote object for nodeId');
return createHandle(context, result); return createHandle(context, result);
@ -162,16 +162,17 @@ export class BidiExecutionContext implements js.ExecutionContextDelegate {
return null; return null;
} }
private async _remoteValueForReference(reference: bidi.Script.RemoteReference) { private async _remoteValueForReference(reference: bidi.Script.RemoteReference, createHandle?: boolean) {
return await this._rawCallFunction('e => e', reference); return await this._rawCallFunction('e => e', reference, createHandle);
} }
private async _rawCallFunction(functionDeclaration: string, arg: bidi.Script.LocalValue): Promise<bidi.Script.RemoteValue> { private async _rawCallFunction(functionDeclaration: string, arg: bidi.Script.LocalValue, createHandle?: boolean): Promise<bidi.Script.RemoteValue> {
const response = await this._session.send('script.callFunction', { const response = await this._session.send('script.callFunction', {
functionDeclaration, functionDeclaration,
target: this._target, target: this._target,
arguments: [arg], arguments: [arg],
resultOwnership: bidi.Script.ResultOwnership.Root, // Necessary for the handle to be returned. // "Root" is necessary for the handle to be returned.
resultOwnership: createHandle ? bidi.Script.ResultOwnership.Root : bidi.Script.ResultOwnership.None,
serializationOptions: { maxObjectDepth: 0, maxDomDepth: 0 }, serializationOptions: { maxObjectDepth: 0, maxDomDepth: 0 },
awaitPromise: true, awaitPromise: true,
userActivation: true, userActivation: true,