Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not wait for navigations while evaluating injected source #1347

Merged
merged 1 commit into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class FrameExecutionContext extends js.ExecutionContext {
this.frame = frame;
}

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

const toDispose: Promise<ElementHandle>[] = [];
Expand All @@ -69,7 +69,7 @@ export class FrameExecutionContext extends js.ExecutionContext {
try {
result = await this.frame._page._frameManager.waitForNavigationsCreatedBy(async () => {
return this._delegate.evaluate(this, returnByValue, pageFunction, ...adopted);
});
}, waitForNavigations ? undefined : { waitUntil: 'nowait' });
} finally {
toDispose.map(handlePromise => handlePromise.then(handle => handle.dispose()));
}
Expand Down Expand Up @@ -97,7 +97,7 @@ export class FrameExecutionContext extends js.ExecutionContext {
${custom.join(',\n')}
])
`;
this._injectedPromise = this.evaluateHandle(source);
this._injectedPromise = this._evaluate(false /* returnByValue */, false /* waitForNavigations */, source);
this._injectedGeneration = selectors._generation;
}
return this._injectedPromise;
Expand Down
6 changes: 3 additions & 3 deletions src/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ export class ExecutionContext {
this._delegate = delegate;
}

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

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

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

_createHandle(remoteObject: any): JSHandle {
Expand Down
5 changes: 3 additions & 2 deletions test/evaluation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,9 @@ module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT,
await page.evaluate(e => e.textContent, element).catch(e => error = e);
expect(error.message).toContain('JSHandle is disposed');
});
// flaky: https://github.com/microsoft/playwright/pull/1277/checks?check_run_id=496501774
it.fail(FFOX && LINUX)('should simulate a user gesture', async({page, server}) => {
it.fail(FFOX)('should simulate a user gesture', async({page, server}) => {
// flaky linux: https://github.com/microsoft/playwright/pull/1277/checks?check_run_id=496501774
// flaky win: https://github.com/microsoft/playwright/pull/1323/checks?check_run_id=501701278
const result = await page.evaluate(() => {
document.body.appendChild(document.createTextNode('test'));
document.execCommand('selectAll');
Expand Down