fix: page.goto should support pages with self requests (#1391) (#1781)

This patch fixes `page.goto` for websites that re-request document URL with javascript.

Fixes #1391.
This commit is contained in:
yujiosaka 2018-01-12 17:16:36 +09:00 committed by Andrey Lushnikov
parent aed7019146
commit c866c175f8
3 changed files with 14 additions and 1 deletions

View File

@ -494,7 +494,10 @@ class Page extends EventEmitter {
const requests = new Map();
const eventListeners = [
helper.addEventListener(this._networkManager, NetworkManager.Events.Request, request => requests.set(request.url(), request))
helper.addEventListener(this._networkManager, NetworkManager.Events.Request, request => {
if (!requests.get(request.url()))
requests.set(request.url(), request);
})
];
const mainFrame = this._frameManager.mainFrame();

View File

@ -0,0 +1,5 @@
<script>
var req = new XMLHttpRequest();
req.open('GET', '/self-request.html');
req.send(null);
</script>

View File

@ -1193,6 +1193,11 @@ describe('Page', function() {
expect(requests.length).toBe(1);
expect(requests[0].url()).toBe(server.EMPTY_PAGE);
});
it('should work with self requesting page', async({page, server}) => {
const response = await page.goto(server.PREFIX + '/self-request.html');
expect(response.status()).toBe(200);
expect(response.url()).toContain('self-request.html');
});
});
describe('Page.waitForNavigation', function() {