Table of Contents

Class TrustedTypePolicyFactory

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll

The TrustedTypePolicyFactory interface of the {{domxref("Trusted Types API", "", "", "nocode")}} creates policies and allows the verification of Trusted Type objects against created policies.

[Value("TrustedTypePolicyFactory")]
public class TrustedTypePolicyFactory
Inheritance
TrustedTypePolicyFactory
Inherited Members

Remarks

Constructors

TrustedTypePolicyFactory()

public TrustedTypePolicyFactory()

Properties

DefaultPolicy

The defaultPolicy read-only property of the TrustedTypePolicyFactory interface returns the default TrustedTypePolicy or null if this is empty.

[Value("defaultPolicy")]
public TrustedTypePolicy? DefaultPolicy { get; }

Property Value

TrustedTypePolicy

A TrustedTypePolicy or null.

Remarks

EmptyHTML

The emptyHTML read-only property of the TrustedTypePolicyFactory interface returns a TrustedHTML object containing an empty string.

[Value("emptyHTML")]
public TrustedHTML EmptyHTML { get; }

Property Value

TrustedHTML

A TrustedHTML object.

Remarks

This object can be used when the application requires an empty string to be inserted into an injection sink.

See also on MDN

EmptyScript

The emptyScript read-only property of the TrustedTypePolicyFactory interface returns a TrustedScript object containing an empty string.

[Value("emptyScript")]
public TrustedScript EmptyScript { get; }

Property Value

TrustedScript

A TrustedScript object.

Remarks

This object can be used when the application requires an empty string to be inserted into an injection sink which is expecting a TrustedScript object.

See also on MDN

Methods

CreatePolicy(string, TrustedTypePolicyOptions)

The createPolicy() method of the TrustedTypePolicyFactory interface creates a TrustedTypePolicy object that implements the rules passed as policyOptions.

[Value("createPolicy")]
public TrustedTypePolicy CreatePolicy(string policyName, TrustedTypePolicyOptions policyOptions = null)

Parameters

policyName string
policyOptions TrustedTypePolicyOptions

Returns

TrustedTypePolicy

A TrustedTypePolicy object.

Remarks

GetAttributeType(string, string, string?, string?)

The getAttributeType() method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element, and if so which Trusted Type is used.

[Value("getAttributeType")]
public string? GetAttributeType(string tagName, string attribute, string? elementNs = null, string? attrNs = null)

Parameters

tagName string
attribute string
elementNs string
attrNs string

Returns

string

A string with one of:Or, null.

Remarks

GetPropertyType(string, string, string?)

The getPropertyType() method of the TrustedTypePolicyFactory interface allows web developers to check if a Trusted Type is required for an element's property.

[Value("getPropertyType")]
public string? GetPropertyType(string tagName, string property, string? elementNs = null)

Parameters

tagName string
property string
elementNs string

Returns

string

A string with one of:Or, null.

Remarks

IsHTML(dynamic)

The isHTML() method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedHTML object.

[Value("isHTML")]
public bool IsHTML(dynamic value)

Parameters

value dynamic

Returns

bool

A {{jsxref("boolean")}} that is true if the object is a valid TrustedHTML object.

Remarks

NOTE

The purpose of the functions isHTML(), IsScript(dynamic), and IsScriptURL(dynamic) is to check if the object is a valid TrustedType object, created by a configured policy.

See also on MDN

IsScript(dynamic)

The isScript() method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScript object.

[Value("isScript")]
public bool IsScript(dynamic value)

Parameters

value dynamic

Returns

bool

A {{jsxref("boolean")}} that is true if the object is a valid TrustedScript object.

Remarks

NOTE

The purpose of the functions isScript(), IsHTML(dynamic), and IsScriptURL(dynamic) is to check if the object is a valid TrustedType object, created by a configured policy.

See also on MDN

IsScriptURL(dynamic)

The isScriptURL() method of the TrustedTypePolicyFactory interface returns true if it is passed a valid TrustedScriptURL object.

[Value("isScriptURL")]
public bool IsScriptURL(dynamic value)

Parameters

value dynamic

Returns

bool

A {{jsxref("boolean")}} that is true if the object is a valid TrustedScriptURL object.

Remarks

NOTE

The purpose of the functions isScriptURL(), IsHTML(dynamic), and IsScript(dynamic) is to check if the object is a valid TrustedType object, created by a configured policy.

See also on MDN