Skip to content

Commit 7c59f9c

Browse files
authored
fix: do not wait for navigations while evaluating injected source (#1347)
1 parent 11c3c11 commit 7c59f9c

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/dom.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class FrameExecutionContext extends js.ExecutionContext {
4545
this.frame = frame;
4646
}
4747

48-
async _evaluate(returnByValue: boolean, pageFunction: string | Function, ...args: any[]): Promise<any> {
48+
async _evaluate(returnByValue: boolean, waitForNavigations: boolean, pageFunction: string | Function, ...args: any[]): Promise<any> {
4949
const needsAdoption = (value: any): boolean => {
5050
return typeof value === 'object' && value instanceof ElementHandle && value._context !== this;
5151
};
@@ -54,7 +54,7 @@ export class FrameExecutionContext extends js.ExecutionContext {
5454
// Only go through asynchronous calls if required.
5555
return await this.frame._page._frameManager.waitForNavigationsCreatedBy(async () => {
5656
return this._delegate.evaluate(this, returnByValue, pageFunction, ...args);
57-
});
57+
}, waitForNavigations ? undefined : { waitUntil: 'nowait' });
5858
}
5959

6060
const toDispose: Promise<ElementHandle>[] = [];
@@ -69,7 +69,7 @@ export class FrameExecutionContext extends js.ExecutionContext {
6969
try {
7070
result = await this.frame._page._frameManager.waitForNavigationsCreatedBy(async () => {
7171
return this._delegate.evaluate(this, returnByValue, pageFunction, ...adopted);
72-
});
72+
}, waitForNavigations ? undefined : { waitUntil: 'nowait' });
7373
} finally {
7474
toDispose.map(handlePromise => handlePromise.then(handle => handle.dispose()));
7575
}
@@ -97,7 +97,7 @@ export class FrameExecutionContext extends js.ExecutionContext {
9797
${custom.join(',\n')}
9898
])
9999
`;
100-
this._injectedPromise = this.evaluateHandle(source);
100+
this._injectedPromise = this._evaluate(false /* returnByValue */, false /* waitForNavigations */, source);
101101
this._injectedGeneration = selectors._generation;
102102
}
103103
return this._injectedPromise;

src/javascript.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ export class ExecutionContext {
3232
this._delegate = delegate;
3333
}
3434

35-
_evaluate(returnByValue: boolean, pageFunction: string | Function, ...args: any[]): Promise<any> {
35+
_evaluate(returnByValue: boolean, waitForNavigations: boolean, pageFunction: string | Function, ...args: any[]): Promise<any> {
3636
return this._delegate.evaluate(this, returnByValue, pageFunction, ...args);
3737
}
3838

3939
evaluate: types.Evaluate = async (pageFunction, ...args) => {
40-
return this._evaluate(true /* returnByValue */, pageFunction, ...args);
40+
return this._evaluate(true /* returnByValue */, true /* waitForNavigations */, pageFunction, ...args);
4141
}
4242

4343
evaluateHandle: types.EvaluateHandle = async (pageFunction, ...args) => {
44-
return this._evaluate(false /* returnByValue */, pageFunction, ...args);
44+
return this._evaluate(false /* returnByValue */, true /* waitForNavigations */, pageFunction, ...args);
4545
}
4646

4747
_createHandle(remoteObject: any): JSHandle {

test/evaluation.spec.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,9 @@ module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT,
230230
await page.evaluate(e => e.textContent, element).catch(e => error = e);
231231
expect(error.message).toContain('JSHandle is disposed');
232232
});
233-
// flaky: https://github.com/microsoft/playwright/pull/1277/checks?check_run_id=496501774
234-
it.fail(FFOX && LINUX)('should simulate a user gesture', async({page, server}) => {
233+
it.fail(FFOX)('should simulate a user gesture', async({page, server}) => {
234+
// flaky linux: https://github.com/microsoft/playwright/pull/1277/checks?check_run_id=496501774
235+
// flaky win: https://github.com/microsoft/playwright/pull/1323/checks?check_run_id=501701278
235236
const result = await page.evaluate(() => {
236237
document.body.appendChild(document.createTextNode('test'));
237238
document.execCommand('selectAll');

0 commit comments

Comments
 (0)