WorkerGlobalScope: securitypolicyviolation イベント

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since August 2016.

securitypolicyviolation イベントは、ウェブワーカーの中でコンテンツセキュリティポリシーの違反が発生したときに発行されます。

ハンドラーは onsecuritypolicyviolation イベントハンドラープロパティを使用するか、EventTarget.addEventListener() を使用して割り当てることができます。

構文

このイベント名を addEventListener() などのメソッドで使用するか、イベントハンドラープロパティを設定するかしてください。

js
addEventListener("securitypolicyviolation", (event) => {});

onsecuritypolicyviolation = (event) => {};

イベント型

下記のコードでは、onsecuritypolicyviolation イベントハンドラープロパティを使用してイベントハンドラー関数を追加するか、addEventListener() メソッドを呼び出す方法を示しています。

js
self.onsecuritypolicyviolation = (e) => {
  // ここで SecurityPolicyViolationEvent e を処理
};

self.addEventListener("securitypolicyviolation", (e) => {
  // ここで SecurityPolicyViolationEvent e を処理
});

仕様書

Specification
Content Security Policy Level 3
# eventdef-globaleventhandlers-securitypolicyviolation

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
securitypolicyviolation event

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報