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

fix: overlay and require-trusted-types-for #5046

Merged
merged 2 commits into from Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Expand Up @@ -3,3 +3,4 @@
!/test/client
coverage
node_modules
examples/client/trusted-types-overlay/app.js
1 change: 1 addition & 0 deletions .prettierignore
Expand Up @@ -3,3 +3,4 @@
coverage
node_modules
CHANGELOG.md
examples/client/trusted-types-overlay/app.js
4 changes: 3 additions & 1 deletion client-src/overlay.js
Expand Up @@ -189,7 +189,9 @@ const createOverlay = (options) => {
*/
function ensureOverlayExists(callback, trustedTypesPolicyName) {
if (containerElement) {
containerElement.innerHTML = "";
containerElement.innerHTML = overlayTrustedTypesPolicy
? overlayTrustedTypesPolicy.createHTML("")
: "";
// Everything is ready, call the callback right away.
callback(containerElement);

Expand Down
3 changes: 3 additions & 0 deletions examples/client/trusted-types-overlay/app.js
Expand Up @@ -4,3 +4,6 @@ const target = document.querySelector("#target");

target.classList.add("pass");
target.textContent = "Success!";

// To display an overlay with an error
(
5 changes: 4 additions & 1 deletion examples/client/trusted-types-overlay/webpack.config.js
Expand Up @@ -9,11 +9,14 @@ const { setup } = require("../../util");
const config = setup({
context: __dirname,
// create error for overlay
entry: "./invalid.js",
entry: "./app.js",
output: {
trustedTypes: { policyName: "webpack" },
},
devServer: {
headers: {
"Content-Security-Policy": "require-trusted-types-for 'script'",
},
client: {
overlay: {
trustedTypesPolicyName: "webpack#dev-overlay",
Expand Down