feat(Chromium): Roll chromium to r511134 (#1153)
This roll includes: - crrev.com/510651 that changes request interception methods in protocol - s/Page.setRequestInterceptionEnabled/Page.setRequestInterception BREAKING CHANGE Page.setRequestInterceptionEnabled is renamed into Page.setRequestInterception.
This commit is contained in:
parent
80ee469429
commit
ce005d480c
16
docs/api.md
16
docs/api.md
@ -75,7 +75,7 @@
|
||||
* [page.setExtraHTTPHeaders(headers)](#pagesetextrahttpheadersheaders)
|
||||
* [page.setJavaScriptEnabled(enabled)](#pagesetjavascriptenabledenabled)
|
||||
* [page.setOfflineMode(enabled)](#pagesetofflinemodeenabled)
|
||||
* [page.setRequestInterceptionEnabled(value)](#pagesetrequestinterceptionenabledvalue)
|
||||
* [page.setRequestInterception(value)](#pagesetrequestinterceptionvalue)
|
||||
* [page.setUserAgent(userAgent)](#pagesetuseragentuseragent)
|
||||
* [page.setViewport(viewport)](#pagesetviewportviewport)
|
||||
* [page.tap(selector)](#pagetapselector)
|
||||
@ -416,7 +416,7 @@ Emitted when an uncaught exception happens within the page.
|
||||
- <[Request]>
|
||||
|
||||
Emitted when a page issues a request. The [request] object is read-only.
|
||||
In order to intercept and mutate requests, see `page.setRequestInterceptionEnabled`.
|
||||
In order to intercept and mutate requests, see `page.setRequestInterception`.
|
||||
|
||||
#### event: 'requestfailed'
|
||||
- <[Request]>
|
||||
@ -979,7 +979,7 @@ The extra HTTP headers will be sent with every request the page initiates.
|
||||
- `enabled` <[boolean]> When `true`, enables offline mode for the page.
|
||||
- returns: <[Promise]>
|
||||
|
||||
#### page.setRequestInterceptionEnabled(value)
|
||||
#### page.setRequestInterception(value)
|
||||
- `value` <[boolean]> Whether to enable request interception.
|
||||
- returns: <[Promise]>
|
||||
|
||||
@ -992,7 +992,7 @@ const puppeteer = require('puppeteer');
|
||||
|
||||
puppeteer.launch().then(async browser => {
|
||||
const page = await browser.newPage();
|
||||
await page.setRequestInterceptionEnabled(true);
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', interceptedRequest => {
|
||||
if (interceptedRequest.url.endsWith('.png') || interceptedRequest.url.endsWith('.jpg'))
|
||||
interceptedRequest.abort();
|
||||
@ -1864,7 +1864,7 @@ If request gets a 'redirect' response, the request is successfully finished with
|
||||
- `failed` - A generic failure occurred.
|
||||
- returns: <[Promise]>
|
||||
|
||||
Aborts request. To use this, request interception should be enabled with `page.setRequestInterceptionEnabled`.
|
||||
Aborts request. To use this, request interception should be enabled with `page.setRequestInterception`.
|
||||
Exception is immediately thrown if the request interception is not enabled.
|
||||
|
||||
#### request.continue([overrides])
|
||||
@ -1875,7 +1875,7 @@ Exception is immediately thrown if the request interception is not enabled.
|
||||
- `headers` <[Object]> If set changes the request HTTP headers
|
||||
- returns: <[Promise]>
|
||||
|
||||
Continues request with optional request overrides. To use this, request interception should be enabled with `page.setRequestInterceptionEnabled`.
|
||||
Continues request with optional request overrides. To use this, request interception should be enabled with `page.setRequestInterception`.
|
||||
Exception is immediately thrown if the request interception is not enabled.
|
||||
|
||||
#### request.failure()
|
||||
@ -1921,13 +1921,13 @@ ResourceType will be one of the following: `document`, `stylesheet`, `image`, `m
|
||||
- returns: <[Promise]>
|
||||
|
||||
Fulfills request with given response. To use this, request interception should
|
||||
be enabled with `page.setRequestInterceptionEnabled`. Exception is thrown if
|
||||
be enabled with `page.setRequestInterception`. Exception is thrown if
|
||||
request interception is not enabled.
|
||||
|
||||
An example of fulfilling all requests with 404 responses:
|
||||
|
||||
```js
|
||||
await page.setRequestInterceptionEnabled(true);
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', request => {
|
||||
request.respond({
|
||||
status: 404,
|
||||
|
@ -22,7 +22,7 @@ const puppeteer = require('puppeteer');
|
||||
|
||||
const browser = await puppeteer.launch();
|
||||
const page = await browser.newPage();
|
||||
await page.setRequestInterceptionEnabled(true);
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', request => {
|
||||
if (request.resourceType === 'image')
|
||||
request.abort();
|
||||
|
@ -106,7 +106,7 @@ class NetworkManager extends EventEmitter {
|
||||
/**
|
||||
* @param {boolean} value
|
||||
*/
|
||||
async setRequestInterceptionEnabled(value) {
|
||||
async setRequestInterception(value) {
|
||||
this._userRequestInterceptionEnabled = value;
|
||||
await this._updateProtocolRequestInterception();
|
||||
}
|
||||
@ -116,7 +116,8 @@ class NetworkManager extends EventEmitter {
|
||||
if (enabled === this._protocolRequestInterceptionEnabled)
|
||||
return;
|
||||
this._protocolRequestInterceptionEnabled = enabled;
|
||||
await this._client.send('Network.setRequestInterceptionEnabled', {enabled});
|
||||
const patterns = enabled ? [{urlPattern: '*'}] : [];
|
||||
await this._client.send('Network.setRequestInterception', {patterns});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -149,8 +149,8 @@ class Page extends EventEmitter {
|
||||
/**
|
||||
* @param {boolean} value
|
||||
*/
|
||||
async setRequestInterceptionEnabled(value) {
|
||||
return this._networkManager.setRequestInterceptionEnabled(value);
|
||||
async setRequestInterception(value) {
|
||||
return this._networkManager.setRequestInterception(value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,7 +34,7 @@
|
||||
"ws": "^3.0.0"
|
||||
},
|
||||
"puppeteer": {
|
||||
"chromium_revision": "510398"
|
||||
"chromium_revision": "511134"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/debug": "0.0.30",
|
||||
|
45
test/test.js
45
test/test.js
@ -1170,9 +1170,9 @@ describe('Page', function() {
|
||||
}));
|
||||
});
|
||||
|
||||
describe('Page.setRequestInterceptionEnabled', function() {
|
||||
describe('Page.setRequestInterception', function() {
|
||||
it('should intercept', SX(async function() {
|
||||
await page.setRequestInterceptionEnabled(true);
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', request => {
|
||||
expect(request.url).toContain('empty.html');
|
||||
expect(request.headers['user-agent']).toBeTruthy();
|
||||
@ -1184,11 +1184,18 @@ describe('Page', function() {
|
||||
const response = await page.goto(EMPTY_PAGE);
|
||||
expect(response.ok).toBe(true);
|
||||
}));
|
||||
it('should stop intercepting', SX(async function() {
|
||||
await page.setRequestInterception(true);
|
||||
page.once('request', request => request.continue());
|
||||
await page.goto(EMPTY_PAGE);
|
||||
await page.setRequestInterception(false);
|
||||
await page.goto(EMPTY_PAGE);
|
||||
}));
|
||||
it('should show custom HTTP headers', SX(async function() {
|
||||
await page.setExtraHTTPHeaders({
|
||||
foo: 'bar'
|
||||
});
|
||||
await page.setRequestInterceptionEnabled(true);
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', request => {
|
||||
expect(request.headers['foo']).toBe('bar');
|
||||
request.continue();
|
||||
@ -1197,7 +1204,7 @@ describe('Page', function() {
|
||||
expect(response.ok).toBe(true);
|
||||
}));
|
||||
it('should be abortable', SX(async function() {
|
||||
await page.setRequestInterceptionEnabled(true);
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', request => {
|
||||
if (request.url.endsWith('.css'))
|
||||
request.abort();
|
||||
@ -1212,7 +1219,7 @@ describe('Page', function() {
|
||||
expect(failedRequests).toBe(1);
|
||||
}));
|
||||
it('should be abortable with custom error codes', SX(async function() {
|
||||
await page.setRequestInterceptionEnabled(true);
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', request => {
|
||||
request.abort('internetdisconnected');
|
||||
});
|
||||
@ -1223,7 +1230,7 @@ describe('Page', function() {
|
||||
expect(failedRequest.failure().errorText).toBe('net::ERR_INTERNET_DISCONNECTED');
|
||||
}));
|
||||
it('should amend HTTP headers', SX(async function() {
|
||||
await page.setRequestInterceptionEnabled(true);
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', request => {
|
||||
const headers = Object.assign({}, request.headers);
|
||||
headers['FOO'] = 'bar';
|
||||
@ -1237,7 +1244,7 @@ describe('Page', function() {
|
||||
expect(request.headers['foo']).toBe('bar');
|
||||
}));
|
||||
it('should fail navigation when aborting main resource', SX(async function() {
|
||||
await page.setRequestInterceptionEnabled(true);
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', request => request.abort());
|
||||
let error = null;
|
||||
await page.goto(EMPTY_PAGE).catch(e => error = e);
|
||||
@ -1245,7 +1252,7 @@ describe('Page', function() {
|
||||
expect(error.message).toContain('Failed to navigate');
|
||||
}));
|
||||
it('should work with redirects', SX(async function() {
|
||||
await page.setRequestInterceptionEnabled(true);
|
||||
await page.setRequestInterception(true);
|
||||
const requests = [];
|
||||
page.on('request', request => {
|
||||
request.continue();
|
||||
@ -1262,7 +1269,7 @@ describe('Page', function() {
|
||||
expect(requests[2].resourceType).toBe('document');
|
||||
}));
|
||||
it('should be able to abort redirects', SX(async function() {
|
||||
await page.setRequestInterceptionEnabled(true);
|
||||
await page.setRequestInterception(true);
|
||||
server.setRedirect('/non-existing.json', '/non-existing-2.json');
|
||||
server.setRedirect('/non-existing-2.json', '/simple.html');
|
||||
page.on('request', request => {
|
||||
@ -1285,7 +1292,7 @@ describe('Page', function() {
|
||||
await page.goto(EMPTY_PAGE);
|
||||
let responseCount = 1;
|
||||
server.setRoute('/zzz', (req, res) => res.end((responseCount++) * 11 + ''));
|
||||
await page.setRequestInterceptionEnabled(true);
|
||||
await page.setRequestInterception(true);
|
||||
|
||||
let spinner = false;
|
||||
// Cancel 2nd request.
|
||||
@ -1301,7 +1308,7 @@ describe('Page', function() {
|
||||
expect(results).toEqual(['11', 'FAILED', '22']);
|
||||
}));
|
||||
it('should navigate to dataURL and fire dataURL requests', SX(async function() {
|
||||
await page.setRequestInterceptionEnabled(true);
|
||||
await page.setRequestInterception(true);
|
||||
const requests = [];
|
||||
page.on('request', request => {
|
||||
requests.push(request);
|
||||
@ -1314,7 +1321,7 @@ describe('Page', function() {
|
||||
expect(requests[0].url).toBe(dataURL);
|
||||
}));
|
||||
it('should navigate to URL with hash and and fire requests without hash', SX(async function() {
|
||||
await page.setRequestInterceptionEnabled(true);
|
||||
await page.setRequestInterception(true);
|
||||
const requests = [];
|
||||
page.on('request', request => {
|
||||
requests.push(request);
|
||||
@ -1329,13 +1336,13 @@ describe('Page', function() {
|
||||
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);
|
||||
await page.setRequestInterception(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 badly encoded URLs', SX(async function() {
|
||||
await page.setRequestInterceptionEnabled(true);
|
||||
await page.setRequestInterception(true);
|
||||
server.setRoute('/malformed?rnd=%911', (req, res) => res.end());
|
||||
page.on('request', request => request.continue());
|
||||
const response = await page.goto(PREFIX + '/malformed?rnd=%911');
|
||||
@ -1344,7 +1351,7 @@ describe('Page', function() {
|
||||
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);
|
||||
await page.setRequestInterception(true);
|
||||
const requests = [];
|
||||
page.on('request', request => {
|
||||
request.continue();
|
||||
@ -1357,7 +1364,7 @@ describe('Page', function() {
|
||||
}));
|
||||
it('should not throw "Invalid Interception Id" if the request was cancelled', SX(async function() {
|
||||
await page.setContent('<iframe></iframe>');
|
||||
await page.setRequestInterceptionEnabled(true);
|
||||
await page.setRequestInterception(true);
|
||||
let request = null;
|
||||
page.on('request', async r => request = r);
|
||||
page.$eval('iframe', (frame, url) => frame.src = url, EMPTY_PAGE),
|
||||
@ -1385,7 +1392,7 @@ describe('Page', function() {
|
||||
|
||||
describe('Request.respond', function() {
|
||||
it('should work', SX(async function() {
|
||||
await page.setRequestInterceptionEnabled(true);
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', request => {
|
||||
request.respond({
|
||||
status: 201,
|
||||
@ -1401,7 +1408,7 @@ describe('Page', function() {
|
||||
expect(await page.evaluate(() => document.body.textContent)).toBe('Yo, page!');
|
||||
}));
|
||||
it('should allow mocking binary responses', SX(async function() {
|
||||
await page.setRequestInterceptionEnabled(true);
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', request => {
|
||||
const imageBuffer = fs.readFileSync(path.join(__dirname, 'assets', 'pptr.png'));
|
||||
request.respond({
|
||||
@ -2257,7 +2264,7 @@ describe('Page', function() {
|
||||
expect(await responseText).toBe('hello world!');
|
||||
}));
|
||||
it('Page.Events.RequestFailed', SX(async function() {
|
||||
await page.setRequestInterceptionEnabled(true);
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', request => {
|
||||
if (request.url.endsWith('css'))
|
||||
request.abort();
|
||||
|
Loading…
Reference in New Issue
Block a user