Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/cdk/private/trusted-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@ function getPolicy(): TrustedTypePolicy | null {
if (typeof window !== 'undefined') {
const ttWindow = window as unknown as {trustedTypes?: TrustedTypePolicyFactory};
if (ttWindow.trustedTypes !== undefined) {
policy = ttWindow.trustedTypes.createPolicy('angular#components', {
createHTML: (s: string) => s,
});
try {
policy = ttWindow.trustedTypes.createPolicy('angular#components', {
createHTML: (s: string) => s,
});
} catch (error) {
// createPolicy can throw if the name is already registered, or if
// window.trustedTypes was DOM-clobbered with an HTML element before
// Angular bootstrapped. trustedHTMLFromString falls back to plain
// strings — sanitization in _setInnerHtml still runs.
console.error(error);
}
}
}
}
Expand Down
Loading