fix: revert ExecutionContext reporting. (#3058)

It turned out that almost any usecase requires helper methods to access
DOM inside the ExecutionContext.

Instead of exposing execution contexts as-is, we should introduce
IsolatedWorld as a first-class citizen that will hold execution contexts
inside.
This commit is contained in:
Andrey Lushnikov
2018-08-09 18:14:21 -07:00
committed by GitHub
parent 28ccf5d795
commit be7626fa5e
6 changed files with 5 additions and 103 deletions

View File

@@ -31,24 +31,9 @@ class ExecutionContext {
this._frame = frame;
this._contextId = contextPayload.id;
this._isDefault = contextPayload.auxData ? !!contextPayload.auxData['isDefault'] : false;
this._name = contextPayload.name;
this._objectHandleFactory = objectHandleFactory;
}
/**
* @return {string}
*/
name() {
return this._name;
}
/**
* @return {boolean}
*/
isDefault() {
return this._isDefault;
}
/**
* @return {?Puppeteer.Frame}
*/

View File

@@ -188,7 +188,6 @@ class FrameManager extends EventEmitter {
this._contextIdToContext.set(contextPayload.id, context);
if (frame)
frame._addExecutionContext(context);
this.emit(FrameManager.Events.ExecutionContextCreated, context);
}
/**
@@ -201,18 +200,14 @@ class FrameManager extends EventEmitter {
this._contextIdToContext.delete(executionContextId);
if (context.frame())
context.frame()._removeExecutionContext(context);
this.emit(FrameManager.Events.ExecutionContextDestroyed, context);
}
_onExecutionContextsCleared() {
const contexts = Array.from(this._contextIdToContext.values());
this._contextIdToContext.clear();
for (const context of contexts) {
for (const context of this._contextIdToContext.values()) {
if (context.frame())
context.frame()._removeExecutionContext(context);
}
for (const context of contexts)
this.emit(FrameManager.Events.ExecutionContextDestroyed, context);
this._contextIdToContext.clear();
}
/**
@@ -281,8 +276,6 @@ class Frame {
this._contextResolveCallback = null;
this._setDefaultContext(null);
this._executionContexts = new Set();
/** @type {!Set<!WaitTask>} */
this._waitTasks = new Set();
this._loaderId = '';
@@ -299,8 +292,7 @@ class Frame {
* @param {!ExecutionContext} context
*/
_addExecutionContext(context) {
this._executionContexts.add(context);
if (context.isDefault())
if (context._isDefault)
this._setDefaultContext(context);
}
@@ -308,8 +300,7 @@ class Frame {
* @param {!ExecutionContext} context
*/
_removeExecutionContext(context) {
this._executionContexts.delete(context);
if (context.isDefault())
if (context._isDefault)
this._setDefaultContext(null);
}
@@ -337,13 +328,6 @@ class Frame {
return this._contextPromise;
}
/**
* @return {!Array<!ExecutionContext>}
*/
executionContexts() {
return Array.from(this._executionContexts);
}
/**
* @param {function()|string} pageFunction
* @param {!Array<*>} args

View File

@@ -121,8 +121,6 @@ class Page extends EventEmitter {
this._frameManager.on(FrameManager.Events.FrameAttached, event => this.emit(Page.Events.FrameAttached, event));
this._frameManager.on(FrameManager.Events.FrameDetached, event => this.emit(Page.Events.FrameDetached, event));
this._frameManager.on(FrameManager.Events.FrameNavigated, event => this.emit(Page.Events.FrameNavigated, event));
this._frameManager.on(FrameManager.Events.ExecutionContextCreated, event => this.emit(Page.Events.ExecutionContextCreated, event));
this._frameManager.on(FrameManager.Events.ExecutionContextDestroyed, event => this.emit(Page.Events.ExecutionContextDestroyed, event));
this._networkManager.on(NetworkManager.Events.Request, event => this.emit(Page.Events.Request, event));
this._networkManager.on(NetworkManager.Events.Response, event => this.emit(Page.Events.Response, event));
@@ -1130,8 +1128,6 @@ Page.Events = {
Metrics: 'metrics',
WorkerCreated: 'workercreated',
WorkerDestroyed: 'workerdestroyed',
ExecutionContextCreated: 'executioncontextcreated',
ExecutionContextDestroyed: 'executioncontextdestroyed',
};