Skip to content

fix: allow evaluate callback to receive args without selector (#2687)#2777

Open
NajoroRabiaza wants to merge 2 commits intogetgauge:masterfrom
NajoroRabiaza:fix-evaluate-args-2687
Open

fix: allow evaluate callback to receive args without selector (#2687)#2777
NajoroRabiaza wants to merge 2 commits intogetgauge:masterfrom
NajoroRabiaza:fix-evaluate-args-2687

Conversation

@NajoroRabiaza
Copy link
Copy Markdown
Contributor

The issue was that when calling evaluate without a selector, there was no clean way to pass args directly to the callback.

You had to write (element, args) => {} even if you didn't need the element at all.

The fix adds a noSelector flag that is set to true when no selector is passed. Inside evalFunc which runs in the browser context, if noSelector is true, the callback is called with just args as the first argument instead of (element, args).

This way you can now write:

await evaluate((args) => { return args[0] + args[1]; }, { args: [10, 20] })

The existing behavior with a selector or without args is not changed at all.

@zabil
Copy link
Copy Markdown
Member

zabil commented Apr 30, 2026

@NajoroRabiaza can you give a better use case on how this change is going to be used?

Also note this change will break the typescript definition of this function. At this point we do not want to change api's.

@NajoroRabiaza
Copy link
Copy Markdown
Contributor Author

Thanks for the feedback! I understand about the TypeScript definition concern. And a real use case would be something like injecting configuration or environment data into the page without needing a specific element, for example await evaluate((args) => { window.__config = args; }, { args: [{ env: 'test' }] }). But I understand if this is not the time to change the API.

@NajoroRabiaza
Copy link
Copy Markdown
Contributor Author

So we'll close this Pull Request ?

@zabil
Copy link
Copy Markdown
Member

zabil commented May 1, 2026

Yes, sorry about that. For the sake of backward compatibility and a stable api. I would recommend closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants