Polyfill for the Trusted Types
npm install trusted-types
!npm bundle size
!Libraries.io dependency status for latest release
!GitHub issues
!npm

First time here? This is a repository hosting the Trusted Types specification draft and the polyfill code. You might want to check out other resources about Trusted Types:
* Introduction for web developers - API description with examples.
* Explainer - introductory explainer (what problem is the API solving?).
* Specification draft - a more comprehensive and formalized description of the Trusted Types API.
* Browser Support - The API is available natively in browsers based on Chromium version 83 and up.
This repository contains a polyfill implementation that allows you to use the API in all web browsers. The compiled versions are stored in dist directory.
``html`
`html`
Polyfill is published as an npm package trusted-types:
`sh`
$ npm install trusted-types
The polyfill supports both CommonJS and ES Modules.
`javascript`
const tt = require('trusted-types'); // or import {tt} from 'trusted-types'
tt.createPolicy(...);
Due to the way the API is designed, it's possible to polyfill the most important
API surface (trustedTypes.createPolicy function) with the following snippet:
`javascript`
if(typeof trustedTypes == 'undefined')trustedTypes={createPolicy:(n, rules) => rules};
It does not enable the enforcement, but allows the creation of policies that
return string values instead of Trusted Types in non-supporting browsers. Since
the injection sinks in those browsers accept strings, the values will be accepted
unless the policy throws an error. This tinyfill code allows most applications
to work in both Trusted-Type-enforcing and a legacy environment.
To build the polyfill yourself (Java required):
`sh`
$ git clone https://github.com/w3c/webappsec-trusted-types/
$ cd trusted-types
$ npm install
$ npm run build
sh
$ npm test
``Cross-browser testing provided by BrowserStack.
See CONTRIBUTING.
Our wiki or the specification may already contain an answer
to your question. If not, please contact us!