chore: follow up to the execution context changes (#104)
This commit is contained in:
parent
b2c31b7317
commit
1a1732407f
|
|
@ -15,6 +15,7 @@ src
|
||||||
node_modules
|
node_modules
|
||||||
.local-chromium
|
.local-chromium
|
||||||
.local-browser
|
.local-browser
|
||||||
|
.local-webkit
|
||||||
.dev_profile*
|
.dev_profile*
|
||||||
.DS_Store
|
.DS_Store
|
||||||
*.swp
|
*.swp
|
||||||
|
|
@ -44,4 +45,4 @@ tsconfig.json
|
||||||
/index.d.ts
|
/index.d.ts
|
||||||
|
|
||||||
# install.js only does stuff for development
|
# install.js only does stuff for development
|
||||||
/install.js
|
/install.js
|
||||||
|
|
|
||||||
|
|
@ -16,17 +16,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
|
import * as frames from '../frames';
|
||||||
import { assert, debugError } from '../helper';
|
import { assert, debugError } from '../helper';
|
||||||
|
import * as js from '../javascript';
|
||||||
import { TimeoutSettings } from '../TimeoutSettings';
|
import { TimeoutSettings } from '../TimeoutSettings';
|
||||||
import { CDPSession } from './Connection';
|
import { CDPSession } from './Connection';
|
||||||
import { EVALUATION_SCRIPT_URL, ExecutionContextDelegate, ExecutionContext, JSHandle, toRemoteObject } from './ExecutionContext';
|
import { EVALUATION_SCRIPT_URL, ExecutionContext, ExecutionContextDelegate, toRemoteObject } from './ExecutionContext';
|
||||||
import * as frames from '../frames';
|
import { ElementHandle } from './JSHandle';
|
||||||
import * as js from '../javascript';
|
|
||||||
import { LifecycleWatcher } from './LifecycleWatcher';
|
import { LifecycleWatcher } from './LifecycleWatcher';
|
||||||
import { NetworkManager, Response } from './NetworkManager';
|
import { NetworkManager, Response } from './NetworkManager';
|
||||||
import { Page } from './Page';
|
import { Page } from './Page';
|
||||||
import { Protocol } from './protocol';
|
import { Protocol } from './protocol';
|
||||||
import { ElementHandle, createJSHandle } from './JSHandle';
|
|
||||||
|
|
||||||
const UTILITY_WORLD_NAME = '__playwright_utility_world__';
|
const UTILITY_WORLD_NAME = '__playwright_utility_world__';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,17 +15,17 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { JugglerSession } from './Connection';
|
import { EventEmitter } from 'events';
|
||||||
import { Page } from './Page';
|
import { TimeoutError } from '../Errors';
|
||||||
import {RegisteredListener, helper, assert} from '../helper';
|
|
||||||
import {TimeoutError} from '../Errors';
|
|
||||||
import {EventEmitter} from 'events';
|
|
||||||
import { JSHandle, ExecutionContext, ExecutionContextDelegate } from './ExecutionContext';
|
|
||||||
import {NavigationWatchdog, NextNavigationWatchdog} from './NavigationWatchdog';
|
|
||||||
import { ElementHandle } from './JSHandle';
|
|
||||||
import { TimeoutSettings } from '../TimeoutSettings';
|
|
||||||
import * as frames from '../frames';
|
import * as frames from '../frames';
|
||||||
|
import { assert, helper, RegisteredListener } from '../helper';
|
||||||
import * as js from '../javascript';
|
import * as js from '../javascript';
|
||||||
|
import { TimeoutSettings } from '../TimeoutSettings';
|
||||||
|
import { JugglerSession } from './Connection';
|
||||||
|
import { ExecutionContext, ExecutionContextDelegate } from './ExecutionContext';
|
||||||
|
import { ElementHandle } from './JSHandle';
|
||||||
|
import { NavigationWatchdog, NextNavigationWatchdog } from './NavigationWatchdog';
|
||||||
|
import { Page } from './Page';
|
||||||
|
|
||||||
export const FrameManagerEvents = {
|
export const FrameManagerEvents = {
|
||||||
FrameNavigated: Symbol('FrameManagerEvents.FrameNavigated'),
|
FrameNavigated: Symbol('FrameManagerEvents.FrameNavigated'),
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ export type JSHandle = js.JSHandle<ElementHandle>;
|
||||||
export class ExecutionContextDelegate implements js.ExecutionContextDelegate<ElementHandle> {
|
export class ExecutionContextDelegate implements js.ExecutionContextDelegate<ElementHandle> {
|
||||||
private _globalObjectId?: string;
|
private _globalObjectId?: string;
|
||||||
_session: TargetSession;
|
_session: TargetSession;
|
||||||
private _contextId: number;
|
_contextId: number;
|
||||||
private _contextDestroyedCallback: () => void;
|
private _contextDestroyedCallback: () => void;
|
||||||
private _executionContextDestroyedPromise: Promise<unknown>;
|
private _executionContextDestroyedPromise: Promise<unknown>;
|
||||||
|
|
||||||
|
|
@ -157,7 +157,7 @@ export class ExecutionContextDelegate implements js.ExecutionContextDelegate<Ele
|
||||||
functionDeclaration: functionText + '\n' + suffix + '\n',
|
functionDeclaration: functionText + '\n' + suffix + '\n',
|
||||||
// TODO(yurys): support executionContextId in WebKit
|
// TODO(yurys): support executionContextId in WebKit
|
||||||
objectId: thisObjectId,
|
objectId: thisObjectId,
|
||||||
arguments: serializableArgs.map(convertArgument.bind(this)),
|
arguments: serializableArgs.map((arg: any) => this._convertArgument(arg)),
|
||||||
returnByValue: false,
|
returnByValue: false,
|
||||||
emulateUserGesture: true
|
emulateUserGesture: true
|
||||||
});
|
});
|
||||||
|
|
@ -217,21 +217,6 @@ export class ExecutionContextDelegate implements js.ExecutionContextDelegate<Ele
|
||||||
return valueFromRemoteObject(response.result);
|
return valueFromRemoteObject(response.result);
|
||||||
}).catch(rewriteError);
|
}).catch(rewriteError);
|
||||||
|
|
||||||
function convertArgument(this: ExecutionContext, arg: JSHandle | any) : Protocol.Runtime.CallArgument{
|
|
||||||
const objectHandle = arg && (arg instanceof js.JSHandle) ? arg : null;
|
|
||||||
if (objectHandle) {
|
|
||||||
if (objectHandle._context !== this)
|
|
||||||
throw new Error('JSHandles can be evaluated only in the context they were created!');
|
|
||||||
if (objectHandle._disposed)
|
|
||||||
throw new Error('JSHandle is disposed!');
|
|
||||||
const remoteObject = toRemoteObject(arg);
|
|
||||||
if (!remoteObject.objectId)
|
|
||||||
return { value: valueFromRemoteObject(remoteObject) };
|
|
||||||
return { objectId: remoteObject.objectId };
|
|
||||||
}
|
|
||||||
return { value: arg };
|
|
||||||
}
|
|
||||||
|
|
||||||
function unserializableToString(arg) {
|
function unserializableToString(arg) {
|
||||||
if (Object.is(arg, -0))
|
if (Object.is(arg, -0))
|
||||||
return '-0';
|
return '-0';
|
||||||
|
|
@ -332,6 +317,22 @@ export class ExecutionContextDelegate implements js.ExecutionContextDelegate<Ele
|
||||||
}
|
}
|
||||||
return 'JSHandle:' + valueFromRemoteObject(object);
|
return 'JSHandle:' + valueFromRemoteObject(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _convertArgument(arg: JSHandle | any) : Protocol.Runtime.CallArgument {
|
||||||
|
const objectHandle = arg && (arg instanceof js.JSHandle) ? arg : null;
|
||||||
|
if (objectHandle) {
|
||||||
|
if (objectHandle._context._delegate !== this)
|
||||||
|
throw new Error('JSHandles can be evaluated only in the context they were created!');
|
||||||
|
if (objectHandle._disposed)
|
||||||
|
throw new Error('JSHandle is disposed!');
|
||||||
|
const remoteObject = toRemoteObject(arg);
|
||||||
|
if (!remoteObject.objectId)
|
||||||
|
return { value: valueFromRemoteObject(remoteObject) };
|
||||||
|
return { objectId: remoteObject.objectId };
|
||||||
|
}
|
||||||
|
return { value: arg };
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const remoteObjectSymbol = Symbol('RemoteObject');
|
const remoteObjectSymbol = Symbol('RemoteObject');
|
||||||
|
|
|
||||||
|
|
@ -17,17 +17,17 @@
|
||||||
|
|
||||||
import * as EventEmitter from 'events';
|
import * as EventEmitter from 'events';
|
||||||
import { TimeoutError } from '../Errors';
|
import { TimeoutError } from '../Errors';
|
||||||
import { Events } from './events';
|
import * as frames from '../frames';
|
||||||
import { assert, debugError, helper, RegisteredListener } from '../helper';
|
import { assert, debugError, helper, RegisteredListener } from '../helper';
|
||||||
|
import * as js from '../javascript';
|
||||||
import { TimeoutSettings } from '../TimeoutSettings';
|
import { TimeoutSettings } from '../TimeoutSettings';
|
||||||
import { TargetSession } from './Connection';
|
import { TargetSession } from './Connection';
|
||||||
import { JSHandle, ExecutionContext, ExecutionContextDelegate } from './ExecutionContext';
|
import { Events } from './events';
|
||||||
|
import { ExecutionContext, ExecutionContextDelegate } from './ExecutionContext';
|
||||||
import { ElementHandle } from './JSHandle';
|
import { ElementHandle } from './JSHandle';
|
||||||
import { NetworkManager, NetworkManagerEvents, Request, Response } from './NetworkManager';
|
import { NetworkManager, NetworkManagerEvents, Request, Response } from './NetworkManager';
|
||||||
import { Page } from './Page';
|
import { Page } from './Page';
|
||||||
import { Protocol } from './protocol';
|
import { Protocol } from './protocol';
|
||||||
import * as frames from '../frames';
|
|
||||||
import * as js from '../javascript';
|
|
||||||
|
|
||||||
export const FrameManagerEvents = {
|
export const FrameManagerEvents = {
|
||||||
FrameNavigatedWithinDocument: Symbol('FrameNavigatedWithinDocument'),
|
FrameNavigatedWithinDocument: Symbol('FrameNavigatedWithinDocument'),
|
||||||
|
|
@ -178,6 +178,7 @@ export class FrameManager extends EventEmitter implements frames.FrameDelegate<E
|
||||||
const data = this._frameData(frame);
|
const data = this._frameData(frame);
|
||||||
this._frames.delete(data.id);
|
this._frames.delete(data.id);
|
||||||
data.id = framePayload.id;
|
data.id = framePayload.id;
|
||||||
|
this._frames.set(data.id, frame);
|
||||||
}
|
}
|
||||||
} else if (isMainFrame) {
|
} else if (isMainFrame) {
|
||||||
// Initial frame navigation.
|
// Initial frame navigation.
|
||||||
|
|
@ -199,7 +200,9 @@ export class FrameManager extends EventEmitter implements frames.FrameDelegate<E
|
||||||
frame._navigated(framePayload.url, framePayload.name);
|
frame._navigated(framePayload.url, framePayload.name);
|
||||||
for (const context of this._contextIdToContext.values()) {
|
for (const context of this._contextIdToContext.values()) {
|
||||||
if (context.frame() === frame) {
|
if (context.frame() === frame) {
|
||||||
(context._delegate as ExecutionContextDelegate)._dispose();
|
const delegate = context._delegate as ExecutionContextDelegate;
|
||||||
|
delegate._dispose();
|
||||||
|
this._contextIdToContext.delete(delegate._contextId);
|
||||||
frame._contextDestroyed(context);
|
frame._contextDestroyed(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -223,6 +226,8 @@ export class FrameManager extends EventEmitter implements frames.FrameDelegate<E
|
||||||
}
|
}
|
||||||
|
|
||||||
_onExecutionContextCreated(contextPayload : Protocol.Runtime.ExecutionContextDescription) {
|
_onExecutionContextCreated(contextPayload : Protocol.Runtime.ExecutionContextDescription) {
|
||||||
|
if (this._contextIdToContext.has(contextPayload.id))
|
||||||
|
return;
|
||||||
if (!contextPayload.isPageContext)
|
if (!contextPayload.isPageContext)
|
||||||
return;
|
return;
|
||||||
const frameId = contextPayload.frameId;
|
const frameId = contextPayload.frameId;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue