Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you Disable css in CasperJS?

Tags:

casperjs

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?

like image 480
wle8300 Avatar asked Dec 28 '13 20:12

wle8300


1 Answers

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).

like image 114
Darren Cook Avatar answered Oct 14 '22 01:10

Darren Cook