Fix Request Interception (#565)
It turned out that either Network.requestIntercepted or Network.requestWillBeSent occasionally report encoded URL. This patch starts decoding URL's when generating request hash. Fixes #558.
This commit is contained in:
parent
ea4f8d78fc
commit
e921a1cc21
@ -122,6 +122,13 @@ class Multimap {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {!Array<!K>}
|
||||||
|
*/
|
||||||
|
keysArray() {
|
||||||
|
return Array.from(this._map.keys());
|
||||||
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
this._map.clear();
|
this._map.clear();
|
||||||
}
|
}
|
||||||
|
@ -340,7 +340,8 @@ helper.tracePublicAPI(Response);
|
|||||||
*/
|
*/
|
||||||
function generateRequestHash(request) {
|
function generateRequestHash(request) {
|
||||||
const hash = {
|
const hash = {
|
||||||
url: request.url,
|
// Decoding is necessary to normalize URLs. @see crbug.com/759388
|
||||||
|
url: decodeURI(request.url),
|
||||||
method: request.method,
|
method: request.method,
|
||||||
postData: request.postData,
|
postData: request.postData,
|
||||||
headers: {},
|
headers: {},
|
||||||
|
22
test/test.js
22
test/test.js
@ -938,6 +938,28 @@ describe('Page', function() {
|
|||||||
expect(requests.length).toBe(1);
|
expect(requests.length).toBe(1);
|
||||||
expect(requests[0].url).toBe(EMPTY_PAGE);
|
expect(requests[0].url).toBe(EMPTY_PAGE);
|
||||||
}));
|
}));
|
||||||
|
it('should work with encoded URLs', SX(async function() {
|
||||||
|
// The requestWillBeSent will report encoded URL, whereas interception will
|
||||||
|
// report URL as-is. @see crbug.com/759388
|
||||||
|
await page.setRequestInterceptionEnabled(true);
|
||||||
|
page.on('request', request => request.continue());
|
||||||
|
const response = await page.goto(PREFIX + '/some nonexisting page');
|
||||||
|
expect(response.status).toBe(404);
|
||||||
|
}));
|
||||||
|
it('should work with encoded URLs - 2', SX(async function() {
|
||||||
|
// The requestWillBeSent will report URL as-is, whereas interception will
|
||||||
|
// report encoded URL for stylesheet. @see crbug.com/759388
|
||||||
|
await page.setRequestInterceptionEnabled(true);
|
||||||
|
const requests = [];
|
||||||
|
page.on('request', request => {
|
||||||
|
request.continue();
|
||||||
|
requests.push(request);
|
||||||
|
});
|
||||||
|
const response = await page.goto(`data:text/html,<link rel="stylesheet" href="${PREFIX}/fonts?helvetica|arial"/>`);
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
expect(requests.length).toBe(2);
|
||||||
|
expect(requests[1].response().status).toBe(404);
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Page.Events.Dialog', function() {
|
describe('Page.Events.Dialog', function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user