nightmare-load-filter
nightmare-load-filter copied to clipboard
Allow optional arguments to be sent along with the filter function
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)
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!