summaryrefslogtreecommitdiffstats
path: root/toolkit/components/antitracking/bouncetrackingprotection/test/browser/file_bounce.html
blob: 2756555fa5899152b1027161a759210a4f710760 (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
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>Bounce!</title>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
  </head>
  <body>
    <p>Nothing to see here...</p>
    <script>
      // Wrap the entire block so we can run async code.
      (async () => {
        let url = new URL(location.href);

        let redirectDelay = url.searchParams.get("redirectDelay");
        if(redirectDelay != null) {
          redirectDelay = Number.parseInt(redirectDelay);
        } else {
          redirectDelay = 50;
        }

        let setState = url.searchParams.get("setState");
        if (setState) {
          let id = Math.random().toString();

          if (setState == "cookie-client") {
            let cookie = document.cookie;

            if (cookie) {
              console.info("Received cookie", cookie);
            } else {
              let newCookie = `id=${id}`;
              console.info("Setting new cookie", newCookie);
              document.cookie = newCookie;
            }
          } else if (setState == "localStorage") {
            let entry = localStorage.getItem("id");

            if (entry) {
              console.info("Found localStorage entry. id", entry);
            } else {
              console.info("Setting new localStorage entry. id", id);
              localStorage.setItem(id, id);
            }
          }
        }

        let target = url.searchParams.get("target");
        if (target) {
          console.info("redirecting to", target);
          setTimeout(() => {
            location.href = target;
          }, redirectDelay);
        }
      })();
    </script>
  </body>
</html>