default-src 'self'
),
+ this page manually loads Chart.min.css
and turns off the automatic style
+ injection by setting Chart.platform.useExternalStylesheet = true;
.
+ diff --git a/docs/getting-started/integration.md b/docs/getting-started/integration.md index bd16145ed7d..d1a265e88cd 100644 --- a/docs/getting-started/integration.md +++ b/docs/getting-started/integration.md @@ -85,9 +85,9 @@ require(['moment'], function() { }); ``` -## Content-Security-Policy +## Content Security Policy -By default, Chart.js injects CSS directly into the DOM. For webpages secured using [Content-Security-Policy (CSP)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy), this requires to allow `style-src 'unsafe-inline'`. For stricter CSP environments, where only `style-src 'self'` is allowed, the following CSS file needs to be manually added to your webpage: +By default, Chart.js injects CSS directly into the DOM. For webpages secured using [`Content-Security-Policy` (CSP)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy), this requires to allow `style-src 'unsafe-inline'`. For stricter CSP environments, where only `style-src 'self'` is allowed, the following CSS file needs to be manually added to your webpage: ```html diff --git a/rollup.config.js b/rollup.config.js index 1341a16d19a..1f0dbbacac5 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -29,7 +29,7 @@ module.exports = [ }), optional({ include: ['moment'] - }), + }) ], output: { name: 'Chart', diff --git a/samples/advanced/content-security-policy.css b/samples/advanced/content-security-policy.css index c1760394437..8e5b8fd8cbb 100644 --- a/samples/advanced/content-security-policy.css +++ b/samples/advanced/content-security-policy.css @@ -1,5 +1,20 @@ .content { max-width: 640px; margin: auto; - padding: 16px 32px; + padding: 1rem; +} + +.note { + font-family: sans-serif; + color: #5050a0; + line-height: 1.4; + margin-bottom: 1rem; + padding: 1rem; +} + +code { + background-color: #f5f5ff; + border: 1px solid #d0d0fa; + border-radius: 4px; + padding: 0.05rem 0.25rem; } diff --git a/samples/advanced/content-security-policy.html b/samples/advanced/content-security-policy.html index 81f06dc3291..c205bfa2a6f 100644 --- a/samples/advanced/content-security-policy.html +++ b/samples/advanced/content-security-policy.html @@ -14,6 +14,11 @@
default-src 'self'
),
+ this page manually loads Chart.min.css
and turns off the automatic style
+ injection by setting Chart.platform.useExternalStylesheet = true;
.
+