Skip to content

Commit 573707f

Browse files
1-dilikelei董梁玮
andauthored
fix(useScriptTag): support passing nonce (#4753)
Co-authored-by: 董梁玮 <14070624+dong-liangwei123@user.noreply.gitee.com>
1 parent 827403e commit 573707f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/core/useScriptTag/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ export interface UseScriptTagOptions extends ConfigurableDocument {
4545
*
4646
*/
4747
attrs?: Record<string, string>
48+
49+
/**
50+
* Nonce value for CSP (Content Security Policy)
51+
* @default undefined
52+
*/
53+
nonce?: string
4854
}
4955

5056
/**
@@ -71,6 +77,7 @@ export function useScriptTag(
7177
defer,
7278
document = defaultDocument,
7379
attrs = {},
80+
nonce = undefined,
7481
} = options
7582
const scriptTag = shallowRef<HTMLScriptElement | null>(null)
7683

@@ -117,7 +124,9 @@ export function useScriptTag(
117124
el.noModule = noModule
118125
if (referrerPolicy)
119126
el.referrerPolicy = referrerPolicy
120-
127+
if (nonce) {
128+
el.nonce = nonce
129+
}
121130
Object.entries(attrs).forEach(([name, value]) => el?.setAttribute(name, value))
122131

123132
// Enables shouldAppend

0 commit comments

Comments
 (0)