Skip to content

✨ Allow setting discovery browser cookies#383

Merged
wwilsman merged 3 commits intomasterfrom
ww/discovery-cookies
Jun 22, 2021
Merged

✨ Allow setting discovery browser cookies#383
wwilsman merged 3 commits intomasterfrom
ww/discovery-cookies

Conversation

@wwilsman
Copy link
Copy Markdown
Contributor

@wwilsman wwilsman commented Jun 22, 2021

Purpose

Sometimes, cookies sent via a Cookie header 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 dedicated cookies option 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.cookies option that can either be an object containing key-value pairs of cookies, or an array containing cookie parameters with name, value, and other cookie properties.

While it was straightforward to add cookies within page initialization, I discovered that a cookie's url or domain property is also required. The cookies' object-to-param mapping was moved up into snapshot config merging so we could default a snapshot's cookie url to 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.

@wwilsman wwilsman added the ✨ enhancement New feature or request label Jun 22, 2021
@wwilsman wwilsman requested a review from Robdel12 June 22, 2021 00:51
@wwilsman wwilsman force-pushed the ww/discovery-cookies branch from 19ac4f2 to a73ba0b Compare June 22, 2021 00:59
@wwilsman wwilsman enabled auto-merge (squash) June 22, 2021 01:01
Copy link
Copy Markdown
Contributor

@Robdel12 Robdel12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏁

@wwilsman wwilsman merged commit 1064745 into master Jun 22, 2021
@wwilsman wwilsman deleted the ww/discovery-cookies branch June 22, 2021 14:18
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨ enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants