-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
50 lines (32 loc) · 1.54 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
---
title: "TrustedTypePolicyFactory: isScript() method"
short-title: isScript()
slug: Web/API/TrustedTypePolicyFactory/isScript
page-type: web-api-instance-method
browser-compat: api.TrustedTypePolicyFactory.isScript
---
{{APIRef("Trusted Types API")}}{{AvailableInWorkers}}
The **`isScript()`** method of the {{domxref("TrustedTypePolicyFactory")}} interface returns true if it is passed a valid {{domxref("TrustedScript")}} object.
> **Note:** The purpose of the functions `isScript()`, {{domxref("TrustedTypePolicyFactory.isHTML","isHTML()")}}, and {{domxref("TrustedTypePolicyFactory.isScriptURL","isScriptURL()")}} is to check if the object is a valid TrustedType object, created by a configured policy.
## Syntax
```js-nolint
isScript(value)
```
### Parameters
- `value`
- : A {{domxref("TrustedScript")}} object.
### Return value
A {{jsxref("boolean")}} that is true if the object is a valid {{domxref("TrustedScript")}} object.
## Examples
In the below example the constant `url` was created by a policy, and therefore `isScriptURL()` returns true. The second example is an attempt to fake an object, and the third is a string. Both of these will return false when passed to `isScriptURL()`.
```js
const myScript = policy.createScript("eval('2 + 2')");
console.log(trustedTypes.isScript(myScript)); // true;
const fake = Object.create(TrustedScript.prototype);
console.log(trustedTypes.isScript(fake)); // false
console.log(trustedTypes.isScript("eval('2 + 2')")); // false
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}