✨ Allow setting discovery browser cookies#383
Merged
Conversation
19ac4f2 to
a73ba0b
Compare
samarsault
pushed a commit
that referenced
this pull request
Mar 3, 2023
Bumps @percy/sdk-utils from 1.0.0-beta.58 to 1.0.0-beta.60. --- updated-dependencies: - dependency-name: "@percy/sdk-utils" dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.
Purpose
Sometimes, cookies sent via a
Cookieheader don't always seem to work (#374). While I couldn't exactly reproduce a scenario where the header wouldn't work, I thought it would be helpful to have a dedicatedcookiesoption anyway. The dedicated option can help avoid confusion for people who are unfamiliar with the associated header, and also allow setting cookies for specific domains or paths.Approach
The config schema was updated to allow a
discovery.cookiesoption that can either be an object containing key-value pairs of cookies, or an array containing cookie parameters withname,value, and other cookie properties.While it was straightforward to add cookies within page initialization, I discovered that a cookie's
urlordomainproperty is also required. The cookies' object-to-param mapping was moved up into snapshot config merging so we could default a snapshot's cookieurlto the snapshot's own URL.However, I then also discovered that even when used within a page session, cookies are stored for the entire browser session. This fact made it difficult to reason about whether to override clashing cookies, or clear cookies for each page. Either scenario would not be viable for concurrent pages with differing cookies.
It was then decided that cookies could not be made into per-snapshot options. Cookie normalization was moved into the browser class. The browser class was also updated to move launch options into class initialization. This makes it so some SDKs, like Storybook, can launch the browser without needing to provide redundant launch options.
Cookies still cannot be set until a page URL is known, since we need to account for default cookie URLs. If we ignored the url/domain requirement and set cookies eagerly, we would not be able to accept a key-value object and users would also need to know the url/domain in advance in their config; which makes the config less reusable for projects with dynamic staging URLs. Due to this, cookies are set (if provided) whenever a page is navigated to, before actual page navigation occurs.
Other changes
While cookies were allowed as per-snapshot options, the per-snapshot debug log output would be merged with global config options. While it would be nice to include global config in per-snapshot logs, it can be done in a much better way in a follow up PR if desired (using log filtering). Now only provided options are logged, without merged config.