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

Chore: add experimentalSkipDomainInjection option #4955

Merged
Merged
2 changes: 2 additions & 0 deletions content/guides/guides/cross-origin-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ property into the visited `text/html` pages. This is why navigations without the
use of the [`cy.origin()`](/api/commands/origin) command are solely scope to the
same superdomain.

::include{file=partials/document-domain-workaround.md}

We understand this is a bit complicated to understand, so we have built a nifty
chart to help clarify the differences!

Expand Down
62 changes: 57 additions & 5 deletions content/guides/references/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,63 @@ creating `e2e` and `component` objects inside your Cypress configuration.
These experiments are available to be specified inside the `e2e` configuration
object:

| Option | Default | Description |
| -------------------------------- | ------- | --------------------------------------------------------------------------------------------------------- |
| `experimentalStudio` | `false` | Generate and save commands directly to your test suite by interacting with your app as an end user would. |
| `experimentalRunAllSpecs` | `false` | Enables the "Run All Specs" UI feature, allowing the execution of multiple specs sequentially. |
| `experimentalOriginDependencies` | `false` | Enables support for `require`/`import` within `cy.origin`. |
| Option | Default | Description |
| --------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------- |
| `experimentalStudio` | `false` | Generate and save commands directly to your test suite by interacting with your app as an end user would. |
| `experimentalRunAllSpecs` | `false` | Enables the "Run All Specs" UI feature, allowing the execution of multiple specs sequentially. |
| `experimentalOriginDependencies` | `false` | Enables support for `require`/`import` within `cy.origin`. |
| `experimentalSkipDomainInjection` | `null` | Removes injecting `document.domain` into `text/html` pages for any sites that match the provided patterns. |

#### Experimental Skip Domain Injection

Under the hood, Cypress
[injects document.domain](/guides/guides/web-security#Examples-of-what-Cypress-does-under-the-hood)
Copy link
Member

Choose a reason for hiding this comment

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

I just read the Examples-of-what-Cypress-does-under-the-hood section. It doesn't state WHY we set document.domain. This is primarily to allow sub-domain navigation correct? maybe call that out here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have a spot for this in the cross origin testing guide. I think I can move the workaround up there and it will fit fairly well

into your test application to lessen the burden of navigation. This is well
described in our [Cross Origin Testing](guides/guides/cross-origin-testing)
guide. However, some sites have compatibility issues with this feature.

The `experimentalSkipDomainInjection` option disables injecting
`document.domain` inside Cypress. When enabled, all cross-origin/subdomain
navigation must use `cy.origin()`, which may make tests a bit more verbose. We
only recommend including your site pattern if you are having issues running
Cypress out of the box and suspect setting `document.domain` is interfering with
your site's ability to render properly.

Before enabling, verify your application is not implementing frame busting
techniques, which you can mitigate with the
[`modifyObstructiveCode`](/guides/references/configuration#modifyObstructiveCode)
and
[`experimentalModifyObstructiveThirdPartyCode`](/guides/guides/web-security#Modifying-Obstructive-Third-Party-Code)
flags.

At this point in time, we are aware of the following sites that require the
`experimentalSkipDomainInjection` option to be set to be tested properly:

- Google
- Salesforce

This flag can be enabled by passing an array of origin URLs or
[minimatch](https://github.com/isaacs/minimatch) glob patterns:

:::cypress-config-example

```js
{
e2e: {
experimentalSkipDomainInjection: [
'*.salesforce.com',
'*.force.com',
'*.google.com',
]
}
}
```

:::

If using other Salesforce domains, such as
[enhanced domains](https://help.salesforce.com/s/articleView?id=sf.domain_name_enhanced.htm&type=5),
you will need to add the correct matching glob pattern.

### Component Testing

Expand Down
13 changes: 13 additions & 0 deletions content/partials/document-domain-workaround.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Alert type="warning">

<strong class="alert-header"><Icon name="exclamation-triangle"></Icon> Disabling
`document.domain` Injection</strong>

In some cases, `document.domain` injection may cause issues. As of Cypress
[v12.4.0](https://on.cypress.io/changelog#12-4-0), disabling `document.domain`
injection is available with the `experimentalSkipDomainInjection` option. Please
read about this
[experiment](/guides/references/experiments#Experimental-Skip-Domain-Injection)
for more information

</Alert>