Skip to content

Commit

Permalink
fix: overlay and require-trusted-types-for (#5046)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Feb 13, 2024
1 parent 7681477 commit e115436
Show file tree
Hide file tree
Showing 8 changed files with 475 additions and 2,521 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit e115436

Please sign in to comment.