Skip to content

Write nonce to <script> tag with setAttribute() #817

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

Merged
merged 1 commit into from
Jul 10, 2025

Conversation

rubenswieringa
Copy link
Contributor

Sets nonce on <script> tag thru setAttribute() instead of HTMLScriptElement.nonce property.

HTMLScriptElement.nonce doesn’t work in all browsers – setAttribute() does.

const script = document.createElement('script');
script.type = 'text/javascript';

script.nonce = 'abc';
script.outerHTML; // '<script type="text/javascript"></script>'

script.setAttribute('nonce', 'abc');
script.outerHTML; // '<script type="text/javascript" nonce="abc"></script>'

Copy link

changeset-bot bot commented Jul 1, 2025

🦋 Changeset detected

Latest commit: 4cc62a4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
react-use-intercom Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

HTMLScriptElement.nonce doesn’t work in all browsers – setAttribute() does.
@devrnt
Copy link
Owner

devrnt commented Jul 10, 2025

Thanks!

@devrnt devrnt merged commit b93d098 into devrnt:main Jul 10, 2025
4 of 5 checks passed
@devrnt
Copy link
Owner

devrnt commented Jul 10, 2025

v5.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants