TrustedScriptURL: toJSON() メソッド
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.
メモ: この機能はウェブワーカー内で利用可能です。
toJSON() は TrustedScriptURL インターフェイスのメソッドで、格納されているデータの JSON 表現を返します。
構文
js
toJSON()
引数
なし。
返値
文字列で、格納されているデータの JSON 表現が入ります。
例
定数 sanitized は、信頼型ポリシーによって作成されたオブジェクトです。toString() メソッドは、サードパーティー製スクリプトを読み込むために安全に使用できる文字列を返します。
js
const sanitized = scriptPolicy.createScriptURL(
"https://example.com/my-script.js",
);
console.log(sanitized.toJSON());
仕様書
| Specification |
|---|
| Trusted Types> # dom-trustedscripturl-tojson> |