summaryrefslogtreecommitdiffstats
path: root/platform/browser/test.html
blob: 32b1aba8e1a2c754c532a27dc94c81c1713c0009 (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
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>uBO Static Network Filtering Engine</title>
</head>
<body>
<script type="module">
    import {
        FilteringContext,
        enableWASM,
        pslInit,
        restart,
    } from './main.js';

    (async ( ) => {
        await enableWASM('.');

        await fetch('./data/effective_tld_names.dat').then(response => {
            return response.text();
        }).then(pslRaw => {
            pslInit(pslRaw);
        });

        const snfe = await Promise.all([
            fetch('./data/easylist.txt').then(response => {
                return response.text();
            }),
            fetch('./data/easyprivacy.txt').then(response => {
                return response.text();
            }),
        ]).then(rawLists => {
            return restart([
                { name: 'easylist', raw: rawLists[0] },
                { name: 'easyprivacy', raw: rawLists[1] },
            ]);
        });

        // Reuse filtering context: it's what uBO does
        const fctxt = new FilteringContext();

        // Tests
        // Not blocked
        fctxt.setDocOriginFromURL('https://www.bloomberg.com/');
        fctxt.setURL('https://www.bloomberg.com/tophat/assets/v2.6.1/that.css');
        fctxt.setType('stylesheet');
        if ( snfe.matchRequest(fctxt) !== 0 ) {
            console.log(snfe.toLogData());
        }

        // Blocked
        fctxt.setDocOriginFromURL('https://www.bloomberg.com/');
        fctxt.setURL('https://securepubads.g.doubleclick.net/tag/js/gpt.js');
        fctxt.setType('script');
        if ( snfe.matchRequest(fctxt) !== 0 ) {
            console.log(snfe.toLogData());
        }

        // Unblocked
        fctxt.setDocOriginFromURL('https://www.bloomberg.com/');
        fctxt.setURL('https://sourcepointcmp.bloomberg.com/ccpa.js');
        fctxt.setType('script');
        if ( snfe.matchRequest(fctxt) !== 0 ) {
            console.log(snfe.toLogData());
        }

        restart();
    })();
</script>
</body>
</html>