Call _setPreview
This commit is contained in:
parent
6e5dfe579d
commit
e8b601ad3d
|
|
@ -61,7 +61,7 @@ export class BidiExecutionContext implements js.ExecutionContextDelegate {
|
||||||
throw new js.JavaScriptErrorInEvaluate('Unexpected response type: ' + JSON.stringify(response));
|
throw new js.JavaScriptErrorInEvaluate('Unexpected response type: ' + JSON.stringify(response));
|
||||||
}
|
}
|
||||||
|
|
||||||
async rawEvaluateHandle(context: js.ExecutionContext, expression: string, handlePreview: string): Promise<js.JSHandle> {
|
async rawEvaluateHandle(context: js.ExecutionContext, expression: string): Promise<js.JSHandle> {
|
||||||
const response = await this._session.send('script.evaluate', {
|
const response = await this._session.send('script.evaluate', {
|
||||||
expression,
|
expression,
|
||||||
target: this._target,
|
target: this._target,
|
||||||
|
|
@ -72,7 +72,7 @@ export class BidiExecutionContext implements js.ExecutionContextDelegate {
|
||||||
});
|
});
|
||||||
if (response.type === 'success') {
|
if (response.type === 'success') {
|
||||||
if ('handle' in response.result)
|
if ('handle' in response.result)
|
||||||
return createHandle(context, response.result, handlePreview);
|
return createHandle(context, response.result);
|
||||||
throw new js.JavaScriptErrorInEvaluate('Cannot get handle: ' + JSON.stringify(response.result));
|
throw new js.JavaScriptErrorInEvaluate('Cannot get handle: ' + JSON.stringify(response.result));
|
||||||
}
|
}
|
||||||
if (response.type === 'exception')
|
if (response.type === 'exception')
|
||||||
|
|
@ -207,11 +207,11 @@ function remoteObjectValue(remoteObject: bidi.Script.RemoteValue): any {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createHandle(context: js.ExecutionContext, remoteObject: bidi.Script.RemoteValue, handlePreview?: string): js.JSHandle {
|
export function createHandle(context: js.ExecutionContext, remoteObject: bidi.Script.RemoteValue): js.JSHandle {
|
||||||
if (remoteObject.type === 'node') {
|
if (remoteObject.type === 'node') {
|
||||||
assert(context instanceof dom.FrameExecutionContext);
|
assert(context instanceof dom.FrameExecutionContext);
|
||||||
return new dom.ElementHandle(context, remoteObject.handle!);
|
return new dom.ElementHandle(context, remoteObject.handle!);
|
||||||
}
|
}
|
||||||
const objectId = 'handle' in remoteObject ? remoteObject.handle : undefined;
|
const objectId = 'handle' in remoteObject ? remoteObject.handle : undefined;
|
||||||
return new js.JSHandle(context, remoteObject.type, handlePreview ?? renderPreview(remoteObject), objectId, remoteObjectValue(remoteObject));
|
return new js.JSHandle(context, remoteObject.type, renderPreview(remoteObject), objectId, remoteObjectValue(remoteObject));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,14 +46,14 @@ export class CRExecutionContext implements js.ExecutionContextDelegate {
|
||||||
return remoteObject.value;
|
return remoteObject.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
async rawEvaluateHandle(context: js.ExecutionContext, expression: string, handlePreview: string): Promise<js.JSHandle> {
|
async rawEvaluateHandle(context: js.ExecutionContext, expression: string): Promise<js.JSHandle> {
|
||||||
const { exceptionDetails, result: remoteObject } = await this._client.send('Runtime.evaluate', {
|
const { exceptionDetails, result: remoteObject } = await this._client.send('Runtime.evaluate', {
|
||||||
expression,
|
expression,
|
||||||
contextId: this._contextId,
|
contextId: this._contextId,
|
||||||
}).catch(rewriteError);
|
}).catch(rewriteError);
|
||||||
if (exceptionDetails)
|
if (exceptionDetails)
|
||||||
throw new js.JavaScriptErrorInEvaluate(getExceptionMessage(exceptionDetails));
|
throw new js.JavaScriptErrorInEvaluate(getExceptionMessage(exceptionDetails));
|
||||||
return createHandle(context, remoteObject, handlePreview);
|
return createHandle(context, remoteObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
async evaluateWithArguments(expression: string, returnByValue: boolean, utilityScript: js.JSHandle, values: any[], handles: js.JSHandle[]): Promise<any> {
|
async evaluateWithArguments(expression: string, returnByValue: boolean, utilityScript: js.JSHandle, values: any[], handles: js.JSHandle[]): Promise<any> {
|
||||||
|
|
@ -131,10 +131,10 @@ function renderPreview(object: Protocol.Runtime.RemoteObject): string | undefine
|
||||||
return object.description;
|
return object.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createHandle(context: js.ExecutionContext, remoteObject: Protocol.Runtime.RemoteObject, handlePreview?: string): js.JSHandle {
|
export function createHandle(context: js.ExecutionContext, remoteObject: Protocol.Runtime.RemoteObject): js.JSHandle {
|
||||||
if (remoteObject.subtype === 'node') {
|
if (remoteObject.subtype === 'node') {
|
||||||
assert(context instanceof dom.FrameExecutionContext);
|
assert(context instanceof dom.FrameExecutionContext);
|
||||||
return new dom.ElementHandle(context, remoteObject.objectId!);
|
return new dom.ElementHandle(context, remoteObject.objectId!);
|
||||||
}
|
}
|
||||||
return new js.JSHandle(context, remoteObject.subtype || remoteObject.type, handlePreview ?? renderPreview(remoteObject), remoteObject.objectId, potentiallyUnserializableValue(remoteObject));
|
return new js.JSHandle(context, remoteObject.subtype || remoteObject.type, renderPreview(remoteObject), remoteObject.objectId, potentiallyUnserializableValue(remoteObject));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,11 @@ export class FrameExecutionContext extends js.ExecutionContext {
|
||||||
);
|
);
|
||||||
})();
|
})();
|
||||||
`;
|
`;
|
||||||
this._injectedScriptPromise = this.rawEvaluateHandle(source, 'InjectedScript');
|
this._injectedScriptPromise = this.rawEvaluateHandle(source)
|
||||||
|
.then(handle => {
|
||||||
|
handle._setPreview('InjectedScript');
|
||||||
|
return handle;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return this._injectedScriptPromise;
|
return this._injectedScriptPromise;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,14 +44,14 @@ export class FFExecutionContext implements js.ExecutionContextDelegate {
|
||||||
return payload.result!.value;
|
return payload.result!.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
async rawEvaluateHandle(context: js.ExecutionContext, expression: string, handlePreview: string): Promise<js.JSHandle> {
|
async rawEvaluateHandle(context: js.ExecutionContext, expression: string): Promise<js.JSHandle> {
|
||||||
const payload = await this._session.send('Runtime.evaluate', {
|
const payload = await this._session.send('Runtime.evaluate', {
|
||||||
expression,
|
expression,
|
||||||
returnByValue: false,
|
returnByValue: false,
|
||||||
executionContextId: this._executionContextId,
|
executionContextId: this._executionContextId,
|
||||||
}).catch(rewriteError);
|
}).catch(rewriteError);
|
||||||
checkException(payload.exceptionDetails);
|
checkException(payload.exceptionDetails);
|
||||||
return createHandle(context, payload.result!, handlePreview);
|
return createHandle(context, payload.result!);
|
||||||
}
|
}
|
||||||
|
|
||||||
async evaluateWithArguments(expression: string, returnByValue: boolean, utilityScript: js.JSHandle, values: any[], handles: js.JSHandle[]): Promise<any> {
|
async evaluateWithArguments(expression: string, returnByValue: boolean, utilityScript: js.JSHandle, values: any[], handles: js.JSHandle[]): Promise<any> {
|
||||||
|
|
@ -134,10 +134,10 @@ function renderPreview(object: Protocol.Runtime.RemoteObject): string | undefine
|
||||||
return String(object.value);
|
return String(object.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createHandle(context: js.ExecutionContext, remoteObject: Protocol.Runtime.RemoteObject, handlePreview?: string): js.JSHandle {
|
export function createHandle(context: js.ExecutionContext, remoteObject: Protocol.Runtime.RemoteObject): js.JSHandle {
|
||||||
if (remoteObject.subtype === 'node') {
|
if (remoteObject.subtype === 'node') {
|
||||||
assert(context instanceof dom.FrameExecutionContext);
|
assert(context instanceof dom.FrameExecutionContext);
|
||||||
return new dom.ElementHandle(context, remoteObject.objectId!);
|
return new dom.ElementHandle(context, remoteObject.objectId!);
|
||||||
}
|
}
|
||||||
return new js.JSHandle(context, remoteObject.subtype || remoteObject.type || '', handlePreview ?? renderPreview(remoteObject), remoteObject.objectId, potentiallyUnserializableValue(remoteObject));
|
return new js.JSHandle(context, remoteObject.subtype || remoteObject.type || '', renderPreview(remoteObject), remoteObject.objectId, potentiallyUnserializableValue(remoteObject));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ export type SmartHandle<T> = T extends Node ? dom.ElementHandle<T> : JSHandle<T>
|
||||||
|
|
||||||
export interface ExecutionContextDelegate {
|
export interface ExecutionContextDelegate {
|
||||||
rawEvaluateJSON(expression: string): Promise<any>;
|
rawEvaluateJSON(expression: string): Promise<any>;
|
||||||
rawEvaluateHandle(context: ExecutionContext, expression: string, handlePreview: string): Promise<JSHandle>;
|
rawEvaluateHandle(context: ExecutionContext, expression: string): Promise<JSHandle>;
|
||||||
evaluateWithArguments(expression: string, returnByValue: boolean, utilityScript: JSHandle, values: any[], handles: JSHandle[]): Promise<any>;
|
evaluateWithArguments(expression: string, returnByValue: boolean, utilityScript: JSHandle, values: any[], handles: JSHandle[]): Promise<any>;
|
||||||
getProperties(object: JSHandle): Promise<Map<string, JSHandle>>;
|
getProperties(object: JSHandle): Promise<Map<string, JSHandle>>;
|
||||||
releaseHandle(handle: JSHandle): Promise<void>;
|
releaseHandle(handle: JSHandle): Promise<void>;
|
||||||
|
|
@ -77,8 +77,8 @@ export class ExecutionContext extends SdkObject {
|
||||||
return this._raceAgainstContextDestroyed(this.delegate.rawEvaluateJSON(expression));
|
return this._raceAgainstContextDestroyed(this.delegate.rawEvaluateJSON(expression));
|
||||||
}
|
}
|
||||||
|
|
||||||
rawEvaluateHandle(expression: string, preview: string): Promise<JSHandle> {
|
rawEvaluateHandle(expression: string): Promise<JSHandle> {
|
||||||
return this._raceAgainstContextDestroyed(this.delegate.rawEvaluateHandle(this, expression, preview));
|
return this._raceAgainstContextDestroyed(this.delegate.rawEvaluateHandle(this, expression));
|
||||||
}
|
}
|
||||||
|
|
||||||
async evaluateWithArguments(expression: string, returnByValue: boolean, values: any[], handles: JSHandle[]): Promise<any> {
|
async evaluateWithArguments(expression: string, returnByValue: boolean, values: any[], handles: JSHandle[]): Promise<any> {
|
||||||
|
|
@ -106,7 +106,11 @@ export class ExecutionContext extends SdkObject {
|
||||||
${utilityScriptSource.source}
|
${utilityScriptSource.source}
|
||||||
return new (module.exports.UtilityScript())(${isUnderTest()});
|
return new (module.exports.UtilityScript())(${isUnderTest()});
|
||||||
})();`;
|
})();`;
|
||||||
this._utilityScriptPromise = this._raceAgainstContextDestroyed(this.delegate.rawEvaluateHandle(this, source, 'UtilityScript'));
|
this._utilityScriptPromise = this._raceAgainstContextDestroyed(this.delegate.rawEvaluateHandle(this, source))
|
||||||
|
.then(handle => {
|
||||||
|
handle._setPreview('UtilityScript');
|
||||||
|
return handle;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return this._utilityScriptPromise;
|
return this._utilityScriptPromise;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ export class WKExecutionContext implements js.ExecutionContextDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async rawEvaluateHandle(context: js.ExecutionContext, expression: string, handlePreview: string): Promise<js.JSHandle> {
|
async rawEvaluateHandle(context: js.ExecutionContext, expression: string): Promise<js.JSHandle> {
|
||||||
try {
|
try {
|
||||||
const response = await this._session.send('Runtime.evaluate', {
|
const response = await this._session.send('Runtime.evaluate', {
|
||||||
expression,
|
expression,
|
||||||
|
|
@ -57,7 +57,7 @@ export class WKExecutionContext implements js.ExecutionContextDelegate {
|
||||||
});
|
});
|
||||||
if (response.wasThrown)
|
if (response.wasThrown)
|
||||||
throw new js.JavaScriptErrorInEvaluate(response.result.description);
|
throw new js.JavaScriptErrorInEvaluate(response.result.description);
|
||||||
return createHandle(context, response.result, handlePreview);
|
return createHandle(context, response.result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw rewriteError(error);
|
throw rewriteError(error);
|
||||||
}
|
}
|
||||||
|
|
@ -137,7 +137,7 @@ function renderPreview(object: Protocol.Runtime.RemoteObject): string | undefine
|
||||||
return object.description;
|
return object.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createHandle(context: js.ExecutionContext, remoteObject: Protocol.Runtime.RemoteObject, handlePreview?: string): js.JSHandle {
|
export function createHandle(context: js.ExecutionContext, remoteObject: Protocol.Runtime.RemoteObject): js.JSHandle {
|
||||||
if (remoteObject.subtype === 'node') {
|
if (remoteObject.subtype === 'node') {
|
||||||
assert(context instanceof dom.FrameExecutionContext);
|
assert(context instanceof dom.FrameExecutionContext);
|
||||||
return new dom.ElementHandle(context as dom.FrameExecutionContext, remoteObject.objectId!);
|
return new dom.ElementHandle(context as dom.FrameExecutionContext, remoteObject.objectId!);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue