Reputation: 2749
I know how to disable images and plugins, but there doesn't seem to be an apparent option to disable css in CasperJS.
Anyone knows how that works?
Upvotes: 6
Views: 1913
Reputation: 12142
This is what worked for me
//filter css
casper.options.onResourceRequested = function(C, requestData, request) {
var accept = requestData.headers[0];
if ( accept.value.indexOf('text/css') !== -1 ) {
console.log('Skipping CSS file: ' + requestData.url);
request.abort();
}
};
How do you Disable css in CasperJS? didn't work
Upvotes: 0
Reputation: 28938
Assuming you want to suppress the loading of all external style sheets, you can do it by aborting requests to load css files, which is done by assigning a function to options.onResourceRequested
:
var casper = require('casper').create();
casper.options.onResourceRequested = function(C, requestData, request) {
if ((/https?:\/\/.+?\.css/gi).test(requestData['url']) || requestData['Content-Type'] == 'text/css') {
console.log('Skipping CSS file: ' + requestData['url']);
request.abort();
}
}
To avoid the usage of inline style sheets, my only idea is to use some JavaScript to remove all styles just after the page has loaded.
If you used SlimerJS with CasperJS then there is almost certainly an option in the Gecko engine to disable CSS (based on the fact that the Web Developer plugin has an option).
Upvotes: 8