File size: 3,027 Bytes
e7a4412
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Virtual Browser</title>
    <style>
        html, body {
            font-family: 'Noto Sans JP', sans-serif;
            margin: 0;
            padding: 0;
            overflow: hidden;
            background: linear-gradient(135deg, #1a1a2e, #16213e);
        }

        #container {
            width: 100vw;
            height: 100vh;
            position: relative;
        }

        #browserFrame {
            width: 100%;
            height: 100%;
            border: none;
        }

        .loading {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0,0,0,0.8);
            display: flex;
            align-items: center;
            justify-content: center;
            color: #fff;
            font-size: 1.2rem;
        }

        #signoutBtn {
            position: fixed;
            top: 1rem;
            right: 1rem;
            padding: 0.5rem 1rem;
            background: var(--accent-color, #ff6b6b);
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            z-index: 1000;
        }
    </style>
</head>
<body>
    <div id="container">
        <button id="signoutBtn">Sign Out</button>
    </div>
    <script>
        // Check authentication
        if (!localStorage.getItem('authToken')) {
            window.close();
        }

        // Handle sign out
        document.getElementById('signoutBtn').onclick = async () => {
            try {
                const response = await fetch('/signout', { method: 'POST' });
                if (response.ok) {
                    localStorage.removeItem('authToken');
                    window.close();
                }
            } catch (error) {
                console.error('Sign out failed:', error);
            }
        };

        // Load browser content
        (async function loadBrowser() {
            try {
                const token = localStorage.getItem('authToken');
                const response = await fetch('/embed-url', {
                    headers: { 'Authorization': `Bearer ${token}` }
                });

                if (!response.ok) throw new Error('Failed to fetch browser URL');

                const { embedURL } = await response.json();
                const iframe = document.createElement('iframe');
                iframe.id = 'browserFrame';
                iframe.src = embedURL;
                document.getElementById('container').appendChild(iframe);
            } catch (error) {
                console.error('Error loading browser:', error);
                const container = document.getElementById('container');
                container.innerHTML = `<div class="loading">Failed to load browser: ${error.message}</div>`;
            }
        })();
    </script>
</body>
</html>