Skip to content

Commit

Permalink
chore: ignore third-party execution contexts (#32437)
Browse files Browse the repository at this point in the history
* Only track main and utility world contexts
* Properly update click metadata
  • Loading branch information
yury-s committed Sep 4, 2024
1 parent cfae7f7 commit d7b9cf2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
7 changes: 4 additions & 3 deletions packages/playwright-core/src/server/chromium/crPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,15 +690,16 @@ class FrameSession {
if (!frame || this._eventBelongsToStaleFrame(frame._id))
return;
const delegate = new CRExecutionContext(this._client, contextPayload);
let worldName: types.World|null = null;
let worldName: types.World;
if (contextPayload.auxData && !!contextPayload.auxData.isDefault)
worldName = 'main';
else if (contextPayload.name === UTILITY_WORLD_NAME)
worldName = 'utility';
else
return;
const context = new dom.FrameExecutionContext(delegate, frame, worldName);
(context as any)[contextDelegateSymbol] = delegate;
if (worldName)
frame._contextCreated(worldName, context);
frame._contextCreated(worldName, context);
this._contextIdToContext.set(contextPayload.id, context);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/playwright-core/src/server/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export function isNonRecoverableDOMError(error: Error) {
export class FrameExecutionContext extends js.ExecutionContext {
readonly frame: frames.Frame;
private _injectedScriptPromise?: Promise<js.JSHandle>;
readonly world: types.World | null;
readonly world: types.World;

constructor(delegate: js.ExecutionContextDelegate, frame: frames.Frame, world: types.World|null) {
constructor(delegate: js.ExecutionContextDelegate, frame: frames.Frame, world: types.World) {
super(frame, delegate, world || 'content-script');
this.frame = frame;
this.world = world;
Expand Down
7 changes: 4 additions & 3 deletions packages/playwright-core/src/server/firefox/ffPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,16 @@ export class FFPage implements PageDelegate {
if (!frame)
return;
const delegate = new FFExecutionContext(this._session, executionContextId);
let worldName: types.World|null = null;
let worldName: types.World;
if (auxData.name === UTILITY_WORLD_NAME)
worldName = 'utility';
else if (!auxData.name)
worldName = 'main';
else
return;
const context = new dom.FrameExecutionContext(delegate, frame, worldName);
(context as any)[contextDelegateSymbol] = delegate;
if (worldName)
frame._contextCreated(worldName, context);
frame._contextCreated(worldName, context);
this._contextIdToContext.set(executionContextId, context);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export class Mouse {

async click(x: number, y: number, options: { delay?: number, button?: types.MouseButton, clickCount?: number } = {}, metadata?: CallMetadata) {
if (metadata)
metadata.point = { x: this._x, y: this._y };
metadata.point = { x, y };
const { delay = null, clickCount = 1 } = options;
if (delay) {
this.move(x, y, { forClick: true });
Expand Down
7 changes: 4 additions & 3 deletions packages/playwright-core/src/server/webkit/wkPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,15 +502,16 @@ export class WKPage implements PageDelegate {
if (!frame)
return;
const delegate = new WKExecutionContext(this._session, contextPayload.id);
let worldName: types.World|null = null;
let worldName: types.World;
if (contextPayload.type === 'normal')
worldName = 'main';
else if (contextPayload.type === 'user' && contextPayload.name === UTILITY_WORLD_NAME)
worldName = 'utility';
else
return;
const context = new dom.FrameExecutionContext(delegate, frame, worldName);
(context as any)[contextDelegateSymbol] = delegate;
if (worldName)
frame._contextCreated(worldName, context);
frame._contextCreated(worldName, context);
this._contextIdToContext.set(contextPayload.id, context);
}

Expand Down

0 comments on commit d7b9cf2

Please sign in to comment.