cypress
cypress copied to clipboard
[Cypress 12.15.0] Failed to execute 'importScripts' on 'WorkerGlobalScope'
Current behavior
We have been using the text-from-image package to extract text from images. This works using the Tesseract OCR engine. But since Cypress version 12.15.0 we have not been able to run tests using this package again. This has limited us to not being able to keep up to date with the latest versions of Cypress. We have had to stay parked in version 12.14.0.
When running any test, the execution fails on BEFORE ALL
:
(uncaught exception)Error: Uncaught NetworkError: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'https://unpkg.com/[email protected]/dist/worker.min.js' failed to load.
Refused to load the script 'https://unpkg.com/[email protected]/dist/worker.min.js' because it violates the following Content Security Policy directive: "script-src 'unsafe-eval'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
Running Cypress test in v12.14 or earlier does not have this problem.
We have read the Changelog 12.15.0, particularly in relation to Experimental CSP Allow List but we have not been successful in resolving it.
This may be a related issue Cypress 12.15 broke the ability to run Web Workers in Cypress tests #27298
Desired behavior
The use of Tesseract OCR should be supported again without any problems, as it used to be before.
Test code to reproduce
Make sure to have installed or added to the package.json
file:
"cypress": "^12.15.0"
"text-from-image": "^1.1.1"
Add to the cypress/support/commands.js
file:
const ReadText = require('text-from-image')
Create a custom command to use the ReadText
:
// This command takes an imageURL parameter and returns a promise
// that resolves to a six-digit confirmation number extracted from the proof-image.
Cypress.Commands.add(
'getConfirmationNumberFromTamperProof',
(imageURL) =>
new Cypress.Promise((resolve, reject) => {
ReadText(imageURL)
.then((text) => {
const confirmationNumber = text.replace(/[^0-9]/g, '').slice(-6)
resolve(confirmationNumber)
})
.catch((err) => {
reject(err)
})
})
)
Here is an example of how we're using the getConfirmationNumberFromProofImage
custom command:
cy.get('[data-qa-id="confirmation-image"]')
.first()
.invoke('attr', 'src')
.then((sourceImage) => {
cy.getConfirmationNumberFromProofImage(sourceImage).then((confirmationNumber) => {
cy.get('[data-qa-id="confirmation-code"]').type(confirmationNumber)
cy.get('[data-qa-id="confirm-proof"]').click()
})
})
Cypress Version
12.15.0
Node version
18.4.0
Operating System
macOS 14.1
Debug Logs
No response
Other
This issue: Cypress 12.15 broke the ability to run Web Workers in cypress tests that was reported 4 months ago, reporting something similar, was fixed in this PR: fix: Fix web worker creation within spec frame maybe it is related.
It is worth noting that we have upgraded to the latest version of Cypress, and it still results in the same error. No response
Experiencing the same problem here on v13.6.2 Is there a workaround available ?
(uncaught exception)Error: Uncaught NetworkError: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'https://unpkg.com/[email protected]/dist/worker.min.js' failed to load.
Experiencing the same problem here on v13.6.2 Is there a workaround available ?
(uncaught exception)Error: Uncaught NetworkError: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'https://unpkg.com/[email protected]/dist/worker.min.js' failed to load.
@burkedavid No workaround found so far, still parked in the 12.14.0 version, how about you?
Have had to Park it also and remove it from package.json as started breaking other tests.
My workaround is to swallow this error. https://docs.cypress.io/api/cypress-api/catalog-of-events#Uncaught-Exceptions
Cypress.on('uncaught:exception', (err, runnable) => {
if (err.message.match(`Uncaught NetworkError: Failed to execute 'importScripts' on 'WorkerGlobalScope'`)) {
return false;
}
return true;
});