summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fullscreen/api/resources/attempt-fullscreen.html
blob: 98cca04516031b8abe89c05065d58ab021afa0b7 (plain)
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
<!DOCTYPE html>
<meta charset="utf-8" />
<title>IFrame Fullscreen API success reporter</title>
<body></body>
<script>
    window.addEventListener("message", async (e) => {
        switch (e.data.action) {
            case "report":
                await sendReport();
                break;
            default:
                parent.postMessage(
                    {
                        report: {
                            api: "fullscreen",
                            result: `Unknown action ${e.data.action}`,
                            frame: window.name,
                        },
                    },
                    "*"
                );
        }
    });

    async function sendReport() {
        let didSucceed = true;
        let error;
        let errorMessage;
        try {
            await document.body.requestFullscreen();
        } catch (e) {
            didSucceed = false;
            error = e.name;
            errorMessage = e.message;
        } finally {
            const data = {
                report: {
                    api: "fullscreen",
                    result: didSucceed,
                    frame: window.name,
                    error,
                    errorMessage,
                },
            };
            parent.postMessage(data, "*");
        }
    }
</script>