TrustedScript: toString() method

Baseline 2026
Newly available

Since February 2026, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Note: This feature is available in Web Workers.

Phương thức toString() của giao diện TrustedScript trả về một chuỗi có thể chèn an toàn vào injection sink.

Cú pháp

js
toString()

Tham số

Không có.

Giá trị trả về

Một chuỗi chứa script đã được xử lý an toàn.

Ví dụ

Hằng số sanitized là đối tượng được tạo thông qua chính sách Trusted Types. Phương thức toString() trả về chuỗi để thực thi an toàn như script.

js
const sanitized = scriptPolicy.createScript("eval('2 + 2')");
console.log(sanitized.toString());

Thông số kỹ thuật

Thông số kỹ thuật
Trusted Types
# trustedscripturl-stringification-behavior

Tương thích trình duyệt