How to disable css in CasperJS?

I know how to disable images and plugins, but there seems to be no obvious way to disable css in CasperJS.

Does anyone know how this works?

+6
casperjs
source share
2 answers

Assuming that you want to suppress the loading of all external stylesheets, you can do this by interrupting requests for loading css files, which is done by assigning the options.onResourceRequested function:

 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 using inline style sheets, my only idea is to use some JavaScript to remove all styles immediately after the page loads.

If you used SlimerJS with CasperJS, then Gecko almost certainly has an option to disable CSS (based on the fact that the web developer plugin has an option).

+8
source share

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 to disable css in CasperJS? does not work

0
source share

All Articles