Make page.url() return URL synchronously.

page.url() is just a shortcut to page.mainFrame().url().

References #39.
This commit is contained in:
Andrey Lushnikov 2017-07-14 14:05:27 -07:00
parent 34a96a8462
commit 560b817d7f
3 changed files with 8 additions and 6 deletions

View File

@ -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.

View File

@ -236,10 +236,10 @@ class Page extends EventEmitter {
}
/**
* @return {!Promise<string>}
* @return {!string}
*/
async url() {
return this.evaluate(() => window.location.href);
url() {
return this.mainFrame().url();
}
/**

View File

@ -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);
}));
});