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
13 changes: 10 additions & 3 deletions src/cdk/private/trusted-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,16 @@ 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 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should console.error here so we know it's failing?

// 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.
}
}
}
}
Expand Down
Loading