summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/keyboard-lock/resources/iframe-lock-helper.html
blob: 3950802f8e12aa90d236ec275329bbe5bb80cba4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE html>
<script>
'use strict';

window.onmessage = message => {
  if (message.data === 'Ready') {
    let onSuccess = () => { parent.postMessage('Failure', '*'); };
    let onError = error => {
      if (error.name == 'InvalidStateError') {
        parent.postMessage('Success', '*');
      } else {
        parent.postMessage('Failure', '*');
      }
    };

    navigator.keyboard.lock().then(onSuccess, onError);
  }
};

</script>