Revert "feat(Page): teach Page.setContent to wait for resources to load (#1152)" (#1312)

This reverts commit 80ee469429.

Lifecycle events are not ready yet to support the setContent scenario.
The prerequisite for this is
https://chromium-review.googlesource.com/c/chromium/src/+/747805 that
might not land soon due to technical concerns.
This commit is contained in:
Andrey Lushnikov 2017-11-07 14:18:05 -08:00 committed by GitHub
parent b58d319926
commit cbe3dc58a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 31 deletions

View File

@ -72,7 +72,7 @@
* [page.reload(options)](#pagereloadoptions) * [page.reload(options)](#pagereloadoptions)
* [page.screenshot([options])](#pagescreenshotoptions) * [page.screenshot([options])](#pagescreenshotoptions)
* [page.select(selector, ...values)](#pageselectselector-values) * [page.select(selector, ...values)](#pageselectselector-values)
* [page.setContent(html, options)](#pagesetcontenthtml-options) * [page.setContent(html)](#pagesetcontenthtml)
* [page.setCookie(...cookies)](#pagesetcookiecookies) * [page.setCookie(...cookies)](#pagesetcookiecookies)
* [page.setExtraHTTPHeaders(headers)](#pagesetextrahttpheadersheaders) * [page.setExtraHTTPHeaders(headers)](#pagesetextrahttpheadersheaders)
* [page.setJavaScriptEnabled(enabled)](#pagesetjavascriptenabledenabled) * [page.setJavaScriptEnabled(enabled)](#pagesetjavascriptenabledenabled)
@ -954,16 +954,9 @@ page.select('select#colors', 'red', 'green', 'blue'); // multiple selections
Shortcut for [page.mainFrame.select()](#frameselectselector-values) Shortcut for [page.mainFrame.select()](#frameselectselector-values)
#### page.setContent(html, options) #### page.setContent(html)
- `html` <[string]> HTML markup to assign to the page. - `html` <[string]> HTML markup to assign to the page.
- `options` <[Object]> Navigation parameters which might have the following properties: - returns: <[Promise]>
- `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout.
- `waitUntil` <[string]|[Array]<[string]>> When to consider setting content complete, defaults to `load`. Given an array of event strings, setting content is considered to be successful after all events have been fired. Events can be either:
- `load` - consider setting content to be finished when the `load` event is fired.
- `domcontentloaded` - consider setting content to be finished when the `DOMContentLoaded` event is fired.
- `networkidle0` - consider setting content to be finished when there are no more than 0 network connections for at least `500` ms.
- `networkidle2` - consider setting content to be finished when there are no more than 2 network connections for at least `500` ms.
- returns: <[Promise]> Promise which resolves when content is set and all events are triggered.
#### page.setCookie(...cookies) #### page.setCookie(...cookies)
- `...cookies` <...[Object]> - `...cookies` <...[Object]>

View File

@ -438,17 +438,13 @@ class Page extends EventEmitter {
/** /**
* @param {string} html * @param {string} html
* @param {!Object=} options
*/ */
async setContent(html, options) { async setContent(html) {
await Promise.all([ await this.evaluate(html => {
this.evaluate(html => { document.open();
document.open(); document.write(html);
document.write(html); document.close();
document.close(); }, html);
}, html),
this.waitForNavigation(options),
]);
} }
/** /**

View File

@ -2302,17 +2302,6 @@ describe('Page', function() {
const result = await page.content(); const result = await page.content();
expect(result).toBe(`${doctype}${expectedOutput}`); expect(result).toBe(`${doctype}${expectedOutput}`);
})); }));
it('should await resources to load', SX(async function() {
const imgPath = '/img.png';
let imgResponse = null;
server.setRoute(imgPath, (req, res) => imgResponse = res);
let loaded = false;
const contentPromise = page.setContent(`<img src="${PREFIX + imgPath}"></img>`).then(() => loaded = true);
await server.waitForRequest(imgPath);
expect(loaded).toBe(false);
imgResponse.end();
await contentPromise;
}));
}); });
describe('Network Events', function() { describe('Network Events', function() {