Skip to content

Commit

Permalink
fix: Fix web worker creation within spec frame (#27313)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbreiding committed Jul 17, 2023
1 parent 1fcdc87 commit 8fc59f4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ _Released 07/18/2023 (PENDING)_
**Bugfixes:**

- Fixed an issue where `cy.writeFile()` would erroneously fail with the error `cy.writeFile() must only be invoked from the spec file or support file`. Fixes [#27097](https://github.com/cypress-io/cypress/issues/27097).
- Fixed an issue where web workers could not be created within a spec. Fixes [#27298](https://github.com/cypress-io/cypress/issues/27298).

## 12.17.1

Expand Down
15 changes: 15 additions & 0 deletions packages/driver/cypress/e2e/e2e/privileged_commands.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ describe('privileged commands', () => {
`)
})

it('allows web workers in spec frame', () => {
const workerScript = `postMessage('hello from worker')`
const blob = new Blob([workerScript], { type: 'application/javascript' })
const workerURL = URL.createObjectURL(blob)
const worker = new Worker(workerURL)

return new Promise<void>((resolve) => {
worker.onmessage = ({ data }) => {
expect(data).to.equal('hello from worker')

resolve()
}
})
})

it('passes in test body .then() callback', () => {
cy.then(() => {
cy.exec('echo "hello"')
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/util/privileged_channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function setSpecContentSecurityPolicy (specWindow) {
const metaEl = specWindow.document.createElement('meta')

metaEl.setAttribute('http-equiv', 'Content-Security-Policy')
metaEl.setAttribute('content', `script-src 'unsafe-eval'`)
metaEl.setAttribute('content', `script-src 'unsafe-eval'; worker-src * data: blob: 'unsafe-eval' 'unsafe-inline'`)
specWindow.document.querySelector('head')!.appendChild(metaEl)
}

Expand Down

4 comments on commit 8fc59f4

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8fc59f4 Jul 17, 2023

Choose a reason for hiding this comment

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

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.17.2/linux-x64/develop-8fc59f442b8837f526b9a13179f65113cc077fc9/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8fc59f4 Jul 17, 2023

Choose a reason for hiding this comment

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

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.17.2/darwin-x64/develop-8fc59f442b8837f526b9a13179f65113cc077fc9/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8fc59f4 Jul 17, 2023

Choose a reason for hiding this comment

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

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.17.2/darwin-x64/develop-8fc59f442b8837f526b9a13179f65113cc077fc9/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 8fc59f4 Jul 17, 2023

Choose a reason for hiding this comment

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

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.17.2/win32-x64/develop-8fc59f442b8837f526b9a13179f65113cc077fc9/cypress.tgz

Please sign in to comment.