nightmare-load-filter icon indicating copy to clipboard operation
nightmare-load-filter copied to clipboard

Allow optional arguments to be sent along with the filter function

Open evaera opened this issue 7 years ago • 1 comments

This allows custom arguments to be sent to the filter function. It works similar to the existing Nightmare api, meaning that you place the arguments you want to send after the filter function when you are calling nightmare.filter. Then, the arguments are available to your filter function as normal parameters that appear after the electron callback.

Example use case that this pull request enables:

nightmare.filter({ urls: ['*'] }, (details, handler, resources) => {
  let cancel = ['mainFrame', ...resources].every(type => details.resourceType !== type)
  return handler({ cancel })
}, resources)

evaera avatar Oct 05 '17 19:10 evaera

For what it's worth, I found this PR handy for filtering external scripts. I manually patched my copy and it worked like a charm.

This also follows an existing pattern in Nightmare called variable lifting, which is a similar way to handle this in nightmare.evaluate().

Please merge if possible!

RickyRomero avatar Mar 12 '18 06:03 RickyRomero