-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathindex.html
More file actions
273 lines (259 loc) · 7.79 KB
/
index.html
File metadata and controls
273 lines (259 loc) · 7.79 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>OneSignal Dev — SDK-4180 Safari VAPID Test</title>
<style>
.in-app-notification {
position: fixed;
top: 20px;
right: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 16px 24px;
border-radius: 12px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
max-width: 350px;
z-index: 10000;
animation: slideIn 0.3s ease-out;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
* {
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
max-width: 720px;
margin: 40px auto;
padding: 0 20px;
color: #1a1a2e;
}
h1 {
font-size: 22px;
margin-bottom: 4px;
}
.subtitle {
color: #666;
margin-bottom: 24px;
}
.card {
background: #f8f9fa;
border: 1px solid #e0e0e0;
border-radius: 10px;
padding: 20px;
margin-bottom: 16px;
}
.card h3 {
margin-top: 0;
}
button {
padding: 10px 20px;
font-size: 14px;
cursor: pointer;
border: none;
border-radius: 6px;
margin-right: 8px;
margin-bottom: 8px;
}
.btn-primary {
background: #e63946;
color: white;
}
.btn-primary:hover {
background: #c1121f;
}
.btn-secondary {
background: #457b9d;
color: white;
}
.btn-secondary:hover {
background: #1d3557;
}
#log {
background: #1a1a2e;
color: #a8dadc;
font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
font-size: 12px;
padding: 16px;
border-radius: 8px;
max-height: 300px;
overflow-y: auto;
white-space: pre-wrap;
word-break: break-all;
}
#log .error {
color: #e63946;
}
#log .success {
color: #2a9d8f;
}
#log .info {
color: #e9c46a;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 14px;
}
td {
padding: 6px 0;
}
td:first-child {
font-weight: 600;
width: 200px;
}
.tag {
display: inline-block;
padding: 2px 8px;
border-radius: 4px;
font-size: 12px;
font-weight: 600;
}
.tag-legacy {
background: #ffc9c9;
color: #c92a2a;
}
.tag-vapid {
background: #b2f2bb;
color: #2b8a3e;
}
.tag-unknown {
background: #e0e0e0;
color: #666;
}
</style>
<script>
// set can a query param ?app_id=your_app_id OR
// create an .env file and set VITE_APP_ID to your app id
const appId = new URLSearchParams(window.location.search).get('app_id') || '%VITE_APP_ID%';
window.OneSignalDeferred = window.OneSignalDeferred || [];
OneSignalDeferred.push(async function (OneSignal) {
OneSignal.Debug.setLogLevel('trace');
OneSignal._isNewVisitor = true;
OneSignal.init({
appId,
safari_web_id: 'web.onesignal.auto.6187ce57-f346-4a86-93e4-7d70d494c000',
notifyButton: {
enable: true,
prenotify: true,
showBadgeAfter: 0,
},
});
});
</script>
</head>
<body>
<div class="card">
<h3>Browser & Safari Push Info</h3>
<table>
<tr>
<td>User Agent</td>
<td id="ua">—</td>
</tr>
<tr>
<td>window.safari exists</td>
<td id="safari-exists">—</td>
</tr>
<tr>
<td>Legacy permission state</td>
<td id="legacy-perm">—</td>
</tr>
<tr>
<td>Legacy deviceToken</td>
<td id="legacy-token">—</td>
</tr>
<tr>
<td>Notification.permission</td>
<td id="notif-perm">—</td>
</tr>
<tr>
<td>PushSubscriptionOptions</td>
<td id="vapid-support">—</td>
</tr>
<tr>
<td>Expected push path</td>
<td id="push-path">—</td>
</tr>
</table>
</div>
<div class="card">
<h3>Actions</h3>
<button class="btn-primary" id="request-perm">Request Permission</button>
<button class="btn-secondary" id="refresh-info">Refresh Info</button>
</div>
<div class="card">
<h3>Log</h3>
<div id="log"></div>
</div>
<script type="module" src="/src/entries/pageSdkInit.ts" defer></script>
<script>
const $ = (id) => document.getElementById(id);
const log = (msg, cls = '') => {
const el = $('log');
const span = document.createElement('span');
if (cls) span.className = cls;
span.textContent = `[${new Date().toLocaleTimeString()}] ${msg}\n`;
el.appendChild(span);
el.scrollTop = el.scrollHeight;
};
function refreshInfo() {
$('ua').textContent = navigator.userAgent;
const hasSafari =
typeof window.safari !== 'undefined' &&
typeof window.safari.pushNotification !== 'undefined';
$('safari-exists').textContent = hasSafari ? 'Yes' : 'No';
if (hasSafari) {
try {
const safariWebId =
OneSignal?.config?.safariWebId ||
'web.onesignal.auto.6187ce57-f346-4a86-93e4-7d70d494c000';
const perm = window.safari.pushNotification.permission(safariWebId);
$('legacy-perm').textContent = perm.permission;
$('legacy-token').textContent = perm.deviceToken || '(null)';
if (perm.permission === 'granted' && perm.deviceToken) {
$('push-path').innerHTML =
'<span class="tag tag-legacy">Legacy Safari Push</span> (existing subscriber)';
} else {
$('push-path').innerHTML =
'<span class="tag tag-vapid">Standard VAPID Push</span> (new user)';
}
} catch (e) {
$('legacy-perm').textContent = 'Error: ' + e.message;
$('legacy-token').textContent = '—';
}
} else {
$('legacy-perm').textContent = 'N/A (not Safari)';
$('legacy-token').textContent = 'N/A';
const isVapid = typeof PushSubscriptionOptions !== 'undefined';
$('push-path').innerHTML = isVapid
? '<span class="tag tag-vapid">Standard VAPID Push</span>'
: '<span class="tag tag-unknown">Push not supported</span>';
}
const vapidSupport = typeof PushSubscriptionOptions !== 'undefined';
$('vapid-support').textContent = vapidSupport ? 'Supported' : 'Not available';
$('notif-perm').textContent =
typeof Notification !== 'undefined' ? Notification.permission : 'N/A';
}
$('request-perm').addEventListener('click', async () => {
log('Requesting push permission...', 'info');
try {
await OneSignal.Notifications.requestPermission();
log('Permission granted!', 'success');
} catch (e) {
log('Error: ' + e.message, 'error');
}
refreshInfo();
});
$('refresh-info').addEventListener('click', refreshInfo);
window.OneSignalDeferred = window.OneSignalDeferred || [];
OneSignalDeferred.push(() => {
log('OneSignal initialized', 'success');
refreshInfo();
});
// Initial info on page load
setTimeout(refreshInfo, 500);
</script>
</body>
</html>