Microsoft Clarity Adds Support for Custom Trusted Types Policies Enhancing Security

August 14, 2025 at 3:06:12 AM

TL;DR Microsoft Clarity now supports custom Trusted Types policies, enhancing security by allowing developers to define their own policies to prevent XSS attacks. This update offers flexibility in handling content, improves compliance, and maintains functionality. Developers can create policies using trustedTypes.createPolicy() and update the Clarity tag with a trustedTypes parameter. Unsupported browsers fall back to default behavior.

Microsoft Clarity Adds Support for Custom Trusted Types Policies Enhancing Security

Microsoft Clarity has introduced support for custom Trusted Types policies, enhancing security by allowing developers to specify their own policies for handling content within applications. Trusted Types is a browser-enforced feature designed to prevent cross-site scripting (XSS) attacks by restricting dangerous web APIs and requiring content to pass through trusted policies before execution.

What Are Trusted Types Policies?

Trusted Types help mitigate malicious code execution by enforcing that any content passed to sensitive web APIs is sanitized and validated through predefined policies.

Custom Trusted Types in Microsoft Clarity

Previously, Clarity supported only a default Trusted Types policy. Now, developers can specify a custom policy by adding an optional parameter to the Clarity tag request in the setup code:

https://www.clarity.ms/tag/<ProjectId>?trustedTypes=<PolicyName>

This update allows tailored security policies suited to specific application needs.

Benefits of Custom Trusted Types

  • Enhanced Security: Ensures only sanitized and validated content executes, reducing XSS risks.
  • Flexibility: Allows different handling for various content types like HTML, scripts, and URLs.
  • Compliance: Helps meet stringent security standards and best practices.

How to Set Up Custom Trusted Types

  1. Create a Trusted Types Policy using trustedTypes.createPolicy(). Example:
const ClarityPolicy = trustedTypes.createPolicy('ClarityPolicy', { 
    createScriptURL: (input) => { 
        if (input.startsWith('https://www.clarity.ms')) { 
            return input; 
        } 
        throw new Error('Untrusted URL'); 
    } 
});
  1. Update the Clarity Tag by adding the trustedTypes parameter:
<script type="text/javascript"> 
    (function(c,l,a,r,i,t,y){ 
        c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)}; 
        t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i+"?trustedTypes=ClarityPolicy"; 
        y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y); 
    })(window, document, "clarity", "script", "<ProjectId>"); 
</script>

If the browser does not support Trusted Types, the script falls back to its default behavior.

Conclusion

The addition of custom Trusted Types policies in Microsoft Clarity offers developers improved security without sacrificing functionality. This feature supports compliance, scalability, and best-in-class web security, giving developers greater control over frontend security while integrating session recording and analytics.

For more technical details, developers can refer to MDN’s Trusted Types documentation.

Have more questions on this topic? Ask our AI assistant for in-depth insights.

Read more from sources 👇

The Only Digital Marketing Feed You'll Ever Need.

Stay informed your way. Tailored updates when and how you want them. 100% Free.

10,000+ Users

500+ Sources

1000+ Tools

Or

Related Posts

Tired of spending too much time creating audits for your clients?

Tired of spending too much time creating audits for your clients?

Featured
Microsoft Clarity makes WordPress analytics easier with new plugin update

Microsoft Clarity makes WordPress analytics easier with new plugin update

Microsoft Clarity
Microsoft Clarity

Official Source

Official Source

Microsoft Clarity is a Official Source. The source has been verified by Swipe Insight team.

Official Source
Microsoft Clarity and UserFeedback Integration Unlocks Deeper User Behavior Insights Trending ️‍🔥

Microsoft Clarity and UserFeedback Integration Unlocks Deeper User Behavior Insights

Microsoft Clarity
Microsoft Clarity

Official Source

Official Source

Microsoft Clarity is a Official Source. The source has been verified by Swipe Insight team.

Official Source
Microsoft Clarity Shopify integration boosts ecommerce sales with deep insights

Microsoft Clarity Shopify integration boosts ecommerce sales with deep insights

Microsoft Clarity
Microsoft Clarity

Official Source

Official Source

Microsoft Clarity is a Official Source. The source has been verified by Swipe Insight team.

Official Source
Microsoft Clarity expands copilot session summary to 250 recordings

Microsoft Clarity expands copilot session summary to 250 recordings

Josh Silverbauer
Josh Silverbauer

Top Creator

Top Analytics Creator

Josh Silverbauer is a Top Analytics Creator. Part of Swipe Insight Select, a curated list of top creators.

Top Analytics Creator
Microsoft Clarity introduces Trends to track and visualize user data over time

Microsoft Clarity introduces Trends to track and visualize user data over time

Microsoft Clarity
Microsoft Clarity

Official Source

Official Source

Microsoft Clarity is a Official Source. The source has been verified by Swipe Insight team.

Official Source
Microsoft Clarity Live Extension Gets Major UI Upgrade for Easier Heatmaps and Recordings

Microsoft Clarity Live Extension Gets Major UI Upgrade for Easier Heatmaps and Recordings

Microsoft Clarity
Microsoft Clarity

Official Source

Official Source

Microsoft Clarity is a Official Source. The source has been verified by Swipe Insight team.

Official Source
Microsoft Clarity launches Flutter SDK for enhanced mobile app analytics and insights

Microsoft Clarity launches Flutter SDK for enhanced mobile app analytics and insights

Microsoft Clarity
Microsoft Clarity

Official Source

Official Source

Microsoft Clarity is a Official Source. The source has been verified by Swipe Insight team.

Official Source

Related Tools

Markifact logo

Markifact

Verified Tool

Verified Tool

Markifact is a Verified Tool. Want to get this badge? Contact us.

Verified Tool

Marketing Workflows Powered by AI

Featured
Marketing Auditor logo

Marketing Auditor

Verified Tool

Verified Tool

Marketing Auditor is a Verified Tool. Want to get this badge? Contact us.

Verified Tool

Automated audits for Google Ads and Analytics.

Get Featured Here

Showcase your tool in this list.

Contact Us
Microsoft Clarity logo

Microsoft Clarity

Verified Tool

Verified Tool

Microsoft Clarity is a Verified Tool. Want to get this badge? Contact us.

Verified Tool

Free heatmaps and session recordings for websites

Analytics
Fullsession logo

Fullsession

Optimize user engagement with precision analytics

Analytics
Fullstory logo

Fullstory

Understand user behavior to improve experiences

Analytics
Hotjar logo

Hotjar

Understand user behavior with heatmaps and recordings

Analytics

Get Featured Here

Showcase your tool in this list.

Contact Us