From cbe3dc58a20d9270856491095cc4d2ee12577c1d Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Tue, 7 Nov 2017 14:18:05 -0800 Subject: [PATCH] Revert "feat(Page): teach Page.setContent to wait for resources to load (#1152)" (#1312) This reverts commit 80ee46942908054dea3bc14e6505bc12718e0b2d. 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. --- docs/api.md | 13 +++---------- lib/Page.js | 16 ++++++---------- test/test.js | 11 ----------- 3 files changed, 9 insertions(+), 31 deletions(-) diff --git a/docs/api.md b/docs/api.md index ee1671cd..97968688 100644 --- a/docs/api.md +++ b/docs/api.md @@ -72,7 +72,7 @@ * [page.reload(options)](#pagereloadoptions) * [page.screenshot([options])](#pagescreenshotoptions) * [page.select(selector, ...values)](#pageselectselector-values) - * [page.setContent(html, options)](#pagesetcontenthtml-options) + * [page.setContent(html)](#pagesetcontenthtml) * [page.setCookie(...cookies)](#pagesetcookiecookies) * [page.setExtraHTTPHeaders(headers)](#pagesetextrahttpheadersheaders) * [page.setJavaScriptEnabled(enabled)](#pagesetjavascriptenabledenabled) @@ -954,16 +954,9 @@ page.select('select#colors', 'red', 'green', 'blue'); // multiple selections Shortcut for [page.mainFrame.select()](#frameselectselector-values) -#### page.setContent(html, options) +#### page.setContent(html) - `html` <[string]> HTML markup to assign to the page. -- `options` <[Object]> Navigation parameters which might have the following properties: - - `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. +- returns: <[Promise]> #### page.setCookie(...cookies) - `...cookies` <...[Object]> diff --git a/lib/Page.js b/lib/Page.js index 4607c870..e55e0a1d 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -438,17 +438,13 @@ class Page extends EventEmitter { /** * @param {string} html - * @param {!Object=} options */ - async setContent(html, options) { - await Promise.all([ - this.evaluate(html => { - document.open(); - document.write(html); - document.close(); - }, html), - this.waitForNavigation(options), - ]); + async setContent(html) { + await this.evaluate(html => { + document.open(); + document.write(html); + document.close(); + }, html); } /** diff --git a/test/test.js b/test/test.js index a47eeb83..f311be26 100644 --- a/test/test.js +++ b/test/test.js @@ -2302,17 +2302,6 @@ describe('Page', function() { const result = await page.content(); 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(``).then(() => loaded = true); - await server.waitForRequest(imgPath); - expect(loaded).toBe(false); - imgResponse.end(); - await contentPromise; - })); }); describe('Network Events', function() {