1const wpush_vapidPublicKey = webpushData.vapidPublicKey 2const swEndpoint = '/tb-webpush-sw' 3const apiHost = 'https://api.webpush.click' 4 5const urlB64ToUint8Array = (base64String) => { 6 const padding = "=".repeat((4 - (base64String.length % 4)) % 4); 7 const base64 = (base64String + padding) 8 .replace(/\-/g, "+") 9 .replace(/_/g, "/"); 10 11 const rawData = window.atob(base64); 12 const outputArray = new Uint8Array(rawData.length); 13 14 for (let i = 0; i < rawData.length; ++i) { 15 outputArray[i] = rawData.charCodeAt(i); 16 } 17 return outputArray; 18} 19 20if ('serviceWorker' in navigator) { 21 22 const subscribePush = async (registration) => { 23 const subscription = await registration.pushManager.subscribe({ 24 userVisibleOnly: true, 25 applicationServerKey: urlB64ToUint8Array(wpush_vapidPublicKey), 26 }); 27 28 const encoding = (PushManager && PushManager.supportedContentEncodings && PushManager.supportedContentEncodings[0]) || 'aes128gcm' 29 30 fetch(`${apiHost}/subscribe`, { 31 method: 'POST', 32 headers: { 33 'Content-Type': 'application/json' 34 }, 35 body: JSON.stringify({ 36 subscription: subscription.toJSON(), 37 encoding, 38 host: window.location.host 39 }) 40 }) 41 } 42 43 window.addEventListener('load', async () => { 44 try { 45 const registration = await navigator.serviceWorker.register(swEndpoint, { 46 scope: '/' // Scope globale 47 }) 48 await navigator.serviceWorker.ready 49 await subscribePush(registration) 50 } catch (e) { 51 console.error('ServiceWorker registration failed: ', e); 52 } 53 }); 54}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.