antvis/G2






The issue has been closed
Content-Security-Policy: Failed to construct 'Worker': Access to the script at #5462
matzeeable posted onGitHub
- G2 Version: 4.2.10
- Platform: All browsers
- Mini Showcase(like screenshots):
We are using this package in a published WordPress plugin (wordpress.org). One of our users cannot use statistics as it seems that G2 cannot work with Content-Security-Policy (CSP).
The user has configured the following CSP header:
Content-Security-Policy: default-src https: 'unsafe-inline' 'unsafe-eval';
Afterward, G2 cannot render any statistics, furthermore it runs into an uncaught exception:
Refused to create a worker from 'blob:https://www.-------.ch/74ff2c72-6e8d-40db-8424-182bd22efc3c' because it violates the following Content Security Policy directive: "default-src https: 'unsafe-inline' 'unsafe-eval'". Note that 'worker-src' was not explicitly set, so 'default-src' is used as a fallback.
Uncaught DOMException: Failed to construct 'Worker': Access to the script at 'blob:https://www.-------.ch/74ff2c72-6e8d-40db-8424-182bd22efc3c' is denied by the document's Content Security Policy.
This is caused by: https://github.com/antvis/algorithm/blob/d0b9a0fbea68cc6f2b26477d30c492d13bb7df9a/packages/graph/src/workers/createWorker.ts#L13
To make this work, we need to tell our users to enable worker-src
with blob:
, but this one our users justifiably reject on the basis of security.
Is it somehow possible to "skip" Web workers when they cannot be used?