Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce --no-request-interception #207

Merged
merged 1 commit into from
Oct 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ var defaults = {
timeout: '2000',
yields: '0',
colors: null,
'async-polling': true
'async-polling': true,
'request-interception': true
};

function args(argv) {
Expand All @@ -37,7 +38,8 @@ function args(argv) {
'mocha-path', 'web-security'],
boolean: ['help', 'version', 'watch', 'cover', 'node', 'wd', 'debug',
'invert', 'recursive', 'colors', 'ignore-ssl-errors', 'browser-field',
'commondir', 'allow-chrome-as-root', 'async-polling', 'dumpio'],
'commondir', 'allow-chrome-as-root', 'async-polling', 'dumpio',
'request-interception'],
alias: {
help: 'h',
version: 'v',
Expand Down
25 changes: 15 additions & 10 deletions lib/chromium.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,21 @@ module.exports = function (b, opts) {
output.write('\n');
});

// Prevent image and font requests from causing error messages:
page.setRequestInterception(true);
page.on('request', function (request) {
if (IGNORE_RESOURCE_TYPES[request.resourceType()]) {
// Respond with 200 ok or a warning is logged:
request.respond({ status: 200 });
} else {
request.continue();
}
});
// This switch can be used to work around an issue in puppeteer when
// running scripts within a web worker. See
// https://github.com/GoogleChrome/puppeteer/issues/4208
if (opts['request-interception']) {
// Prevent image and font requests from causing error messages:
page.setRequestInterception(true);
page.on('request', function (request) {
if (IGNORE_RESOURCE_TYPES[request.resourceType()]) {
// Respond with 200 ok or a warning is logged:
request.respond({ status: 200 });
} else {
request.continue();
}
});
}

// We need a "real" web page loaded from a URL, or things like
// localStorage are disabled.
Expand Down
7 changes: 7 additions & 0 deletions test/args-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('args', function () {
assert.equal(opts['ignore-ssl-errors'], false);
assert.equal(opts['browser-field'], true);
assert.equal(opts.commondir, true);
assert.equal(opts['request-interception'], true);
});

it('parses --reporter', function () {
Expand Down Expand Up @@ -323,6 +324,12 @@ describe('args', function () {
assert.equal(opts['web-security'], false);
});

it('parses --no-request-interception', function () {
var opts = args(['--no-request-interception']);

assert.equal(opts['request-interception'], false);
});

it('fails with invert but no grep option', function (done) {
run('passes', ['--invert'], function (code, stdout) {
assert.equal(code, 1);
Expand Down
10 changes: 10 additions & 0 deletions test/chromium-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,16 @@ describe('chromium', function () {
});
});

it('allows to turn off request interception', function (done) {
run('requests', ['-R', 'tap', '--no-request-interception'],
function (code, stdout, stderr) {
assert.equal(stderr,
'Failed to load resource: net::ERR_FILE_NOT_FOUND\n');
assert.equal(code, 0);
done();
});
});

context('https-server with a port value given', function () {
var server;
var port;
Expand Down