MCPcopy Create free account
hub / github.com/googlemaps/js-api-loader / getPolicy

Function getPolicy

src/setScriptSrc.ts:27–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

25 * when Trusted Types is unsupported, blocked by CSP, or already registered.
26 */
27function getPolicy(): Policy {
28 if (policy) {
29 return policy;
30 }
31
32 const trustedTypes = (globalThis as TrustedTypesGlobals).trustedTypes;
33
34 if (!trustedTypes) {
35 policy = fallbackPolicy;
36 return policy;
37 }
38
39 try {
40 policy = trustedTypes.createPolicy(TRUSTED_TYPES_POLICY_NAME, {
41 createScriptURL: (url: string) => url,
42 });
43 } catch (e) {
44 logDevWarning(
45 MSG_TRUSTED_TYPES_POLICY_FAILED(TRUSTED_TYPES_POLICY_NAME, e)
46 );
47 policy = fallbackPolicy;
48 }
49
50 return policy;
51}
52
53export function setScriptSrc(script: HTMLScriptElement, src: string): void {
54 script.src = getPolicy().createScriptURL(src) as string;

Callers 1

setScriptSrcFunction · 0.85

Calls 1

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…