fix(setContent): call window.stop() before setting new content (#323)

This ensures that previous loading activity is suppressed and all network requests are canceled.
This commit is contained in:
Dmitry Gozman 2019-12-20 15:30:12 -08:00 committed by GitHub
parent 2673ea90d9
commit 56a48559c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -431,6 +431,7 @@ export class Frame {
if (this._page._delegate.needsLifecycleResetOnSetContent()) if (this._page._delegate.needsLifecycleResetOnSetContent())
this._page._frameManager.frameLifecycleEvent(this._id, 'clear'); this._page._frameManager.frameLifecycleEvent(this._id, 'clear');
await context.evaluate(html => { await context.evaluate(html => {
window.stop();
document.open(); document.open();
document.write(html); document.write(html);
document.close(); document.close();

View File

@ -489,9 +489,9 @@ module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROME
return page.setContent(`<script src='networkidle.js'></script>`, { waitUntil: 'networkidle2' }); return page.setContent(`<script src='networkidle.js'></script>`, { waitUntil: 'networkidle2' });
}, true); }, true);
}); });
xit('should wait for networkidle0 in setContent with request from previous navigation', async({page, server}) => { it.skip(FFOX)('should wait for networkidle0 in setContent with request from previous navigation', async({page, server}) => {
// TODO: there are two issues here which combined fail the test: // TODO: there are two issues here which combined fail the test in firefox:
// - setContent implementation does not cancel all outstanding requests; // - calling window.stop() does not cancel all outstanding requests in firefox;
// - we do not reset inflight request counter on lifecycle clear, so we wait for // - we do not reset inflight request counter on lifecycle clear, so we wait for
// the first request indefinitely. // the first request indefinitely.
// Note that we cannot just reset inflight request counter, because the current navigation // Note that we cannot just reset inflight request counter, because the current navigation
@ -503,7 +503,7 @@ module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROME
return page.setContent(`<script src='networkidle.js'></script>`, { waitUntil: 'networkidle0' }); return page.setContent(`<script src='networkidle.js'></script>`, { waitUntil: 'networkidle0' });
}, true); }, true);
}); });
xit('should wait for networkidle2 in setContent with request from previous navigation', async({page, server}) => { it.skip(FFOX)('should wait for networkidle2 in setContent with request from previous navigation', async({page, server}) => {
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);
server.setRoute('/foo.js', () => {}); server.setRoute('/foo.js', () => {});
await page.setContent(`<script>fetch('foo.js');</script>`); await page.setContent(`<script>fetch('foo.js');</script>`);