Add pre-load content filtering to your Nightmare scripts.
Require the library and pass the Nightmare library as a reference to attach the plugin actions:
var Nightmare = require('nightmare');
require('nightmare-load-filter')(Nightmare);
Adds a prerequest call to fn
filtered to the URLs specified in filter
. The fn
parameter must be a function that accepts details and a callback. When complete, the callback must specify a response object, even if it is empty. Note that filter
is of the same form and works in the same way that the Electron filter does. See the onBeforeRequest
documentation in the Electron documentation for more information.
yield nightmare
.filter({
urls:[
'http://example.com'
]
}, function(details, cb){
//cancel a specific file
return cb({cancel: (details.url === 'http://example.com/some-resource.js')});
})
.goto('http://example.com');