Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow optional arguments to be sent along with the filter function #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

evaera
Copy link

@evaera evaera commented Oct 5, 2017

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)

@RickyRomero
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants