diff --git a/docs/api.md b/docs/api.md index 6f63b977..32b5f2e8 100644 --- a/docs/api.md +++ b/docs/api.md @@ -353,7 +353,9 @@ In case of multiple pages in one browser, each page can have its own viewport si - returns: <[Promise]> Promise which resolves when the value is set. #### page.url() -- returns: <[Promise]<[string]>> Promise which resolves with the current page url. +- returns: <[string]> Current page url. + +This is a shortcut for [page.mainFrame().url()](#frameurl) #### page.userAgent() - returns: <[string]> Returns user agent. diff --git a/lib/Page.js b/lib/Page.js index e090c7b2..9bedfe99 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -236,10 +236,10 @@ class Page extends EventEmitter { } /** - * @return {!Promise} + * @return {!string} */ - async url() { - return this.evaluate(() => window.location.href); + url() { + return this.mainFrame().url(); } /** diff --git a/test/test.js b/test/test.js index 79a2e95d..81f2403a 100644 --- a/test/test.js +++ b/test/test.js @@ -778,9 +778,9 @@ describe('Puppeteer', function() { describe('Page.url', function() { it('should work', SX(async function() { - expect(await page.url()).toBe('about:blank'); + expect(page.url()).toBe('about:blank'); await page.navigate(EMPTY_PAGE); - expect(await page.url()).toBe(EMPTY_PAGE); + expect(page.url()).toBe(EMPTY_PAGE); })); });