Skip to content

setTrustedTypesPolicy()

setTrustedTypesPolicy(policy: TrustedTypesPolicy): void

Defined in: util/trusted_types.ts:30

Sets the policy the library creates its trusted values with, for a page that enforces Trusted Types. Call it before creating a map.

Parameters

Parameter Type Description
policy TrustedTypesPolicy A policy from trustedTypes.createPolicy, or undefined to remove it.

Returns

void

Example

setTrustedTypesPolicy(trustedTypes.createPolicy('my-map', {
    createHTML: (html) => html,
    createScriptURL: (url) => {
        if (!new URL(url, location.href).href.startsWith(`${location.origin}/`)) throw new TypeError(`Blocked script URL ${url}`);
        return url;
    }
}));