fix: allow evaluate callback to receive args without selector (#2687)#2777
Open
NajoroRabiaza wants to merge 2 commits intogetgauge:masterfrom
Open
fix: allow evaluate callback to receive args without selector (#2687)#2777NajoroRabiaza wants to merge 2 commits intogetgauge:masterfrom
NajoroRabiaza wants to merge 2 commits intogetgauge:masterfrom
Conversation
…ge#2687) Signed-off-by: NajoroRabiaza <hei.najoro.2@gmail.com>
Member
|
@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. |
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. |
Contributor
Author
|
So we'll close this Pull Request ? |
Member
|
Yes, sorry about that. For the sake of backward compatibility and a stable api. I would recommend closing this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
The existing behavior with a selector or without args is not changed at all.