if (navigator.getBattery) {
navigator.getBattery().then((battery) => {
// battery.level (0 - 1)
// battery.charging (true, false)
battery.addEventListener('chargingchange', function(event) { this ... });
battery.addEventListener('levelchange', function(event) { this ... });
battery.addEventListener('chargingtimechange', function(event) { this ... });
battery.addEventListener('dischargingtimechange', function(event) { this ... });
});
}
// document.hidden (true, false)
// document.visibilityState (visible, hidden, prerender)
document.addEventListener('visibilitychange', (event) => {});
// navigator.onLine (true, false)
window.addEventListener('offline', (event) => {});
window.addEventListener('online', (event) => {});
// Notification.permission (denied, granted, default)
Notification.requestPermission().then((permission) => {});
new Notification("A fancy notification", options);
navigator.vibrate(500);
navigator.vibrate([500, 250, 500, 250, 500, 250, 500, 250, 500, 250, 500]);
navigator.vibrate(0); // stop vibration
// navigator.connection.type (bluetooth, cellular, ethernet, wifi, ...)
// navigator.connection.downlink
// navigator.connection.downlinkMax
// navigator.connection.effectiveType (slow-2g, 2g, 3g, 4g)
// navigator.connection.saveData (true, false)
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js');
}
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/sw.js', {scope: './'})
.then((registration) => { ... })
.catch((error) => { ... });
});
}
self.addEventListener('install', (event) => { ... }); // InstallEvent
self.addEventListener('activate', (event) => { ... }); // ExtendableEvent
self.addEventListener('message', (event) => { ... }); // MessageEvent
self.addEventListener('fetch', (event) => { ... }); // FetchEvent
self.addEventListener('sync', (event) => { ... }); // SyncEvent
self.addEventListener('push', (event) => { ... }); // PushEvent
caches.open(name).then((cache) => {}); // CacheStorage
caches.has(name).then((boolean) => {}); // CacheStorage
caches.keys(name).then((array) => {}); // CacheStorage
caches.delete(name).then((boolean) => {}); // CacheStorage
cache.match(request, options)
cache.matchAll(request, options)
cache.add(request)
cache.addAll(requests)
cache.put(request, response)
cache.delete(request, options)
cache.keys(request, options)
// const applicationServerKey = urlBase64ToUint8Array(applicationServerPublicKey);
navigator.serviceWorker.register('/sw.js').then((registration) => {
// user interaction, then:
registration.pushManager.getSubscription().then((subscription) => {
if (subscription == null) {
registration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: applicationServerKey
})
.then((newSubscription) => { /* store on server */ })
.catch((error) => {});
}
}, (error) => {});
});
self.addEventListener('push', (event) => {
const text = event.data.text();
const title = 'Push notification!';
const options = {
body: text
};
event.waitUntil(self.registration.showNotification(title, options));
});
const webpush = require('web-push');
const vapidKeys = {
publicKey: /* public key */,
privateKey: /* private key */
}
webpush.setVapidDetails(
'mailto:some@example.com',
vapidKeys.publicKey,
vapidKeys.privateKey
);
webpush.sendNotification(subscription, text);
navigator.serviceWorker.register('/sw.js').then((registration) => {
registration.sync.register('web-api-sync');
});
self.addEventListener('sync', (event) => {
if (event.tag === 'web-api-sync') {
/* do sync stuff */
}
});
const utterance = new SpeechSynthesisUtterance('Hallo Welt!');
// lang, pitch, rate, voice, volume
utterance.lang = 'de'
speechSynthesis.speak(utterance);
const grammar = '#JSGF V1.0; grammar ...';
const recognition = new webkitSpeechRecognition();
const speechRecognitionList = new webkitSpeechGrammarList();
speechRecognitionList.addFromString(grammar, 1);
recognition.grammars = speechRecognitionList;
recognition.lang = 'en-US';
recognition.interimResults = false;
recognition.maxAlternatives = 1;
recognition.onresult = (event) => {}
recognition.start();
let options = {
filters: [
{services: ['heart_rate']}
],
optionalServices: ['battery_service']
}
navigator.bluetooth.requestDevice([options]).then((bluetoothDevice) => { ... })
navigator.share({
title: 'Web-APIs',
text: 'Check out this talk — it rocks!',
url: 'https://giftkugel.github.io/talks/web-api.html#/'
})
.then(() => console.log('Yay!'))
.catch((error) => console.log('D´oh', error));
// Request USB device
device = navigator.usb.requestDevice({
filters: [{
vendorId: 3368,
productId: 516
}]
}).then((devices) => { ... });
// Get already requested devices
navigator.usb.getDevices().then((requestedDevice) => { ... });
device.open()
.then(() => device.selectConfiguration(1)) // Select configuration #1 for the device.
.then(() => device.claimInterface(2)) // Request exclusive control over interface #2.
.then(() => device.controlTransferOut({ options })) // Ready to receive data
.then(() => device.transferIn(5, 64)) // Waiting for 64 bytes of data from endpoint #5.
.then(result => { ... })
.catch(error => { console.log(error); });
// Create credentials
const pc = new PasswordCredential({
id: 'username',
name: 'display name',
iconURL: 'https://www.example.com/icon.jpg',
password: 'secret'
});
// Store
navigator.credentials.store(pc).then(() => { ... });
// Request credentials
navigator.credentials.get({
password: true,
mediation: 'optional'
}).then(passwordCredential => { ... });
// Create credentials
navigator.credentials.create({
password: {
id: 'username',
name: 'display name',
iconURL: 'https://www.example.com/icon.jpg',
password: 'secret'
}
}).then((pc) => { ... store ... });
Server-Timing = #server-timing-metric
server-timing-metric = metric-name *( OWS ";" OWS server-timing-param )
metric-name = token
server-timing-param = server-timing-param-name OWS "=" OWS server-timing-param-value
server-timing-param-name = token
server-timing-param-value = token / quoted-string
HTTP/1.1 200 OK
...
Server-Timing: longtask; dur=5000.4277; desc="The long task is running"
const perfEntries = window.performance.getEntriesByType("navigation");
// PerformanceNavigationTiming
perfEntries[0].connectStart
perfEntries[0].connectEnd
perfEntries[0].domComplete
perfEntries[0].domContentLoadedEventStart
perfEntries[0].domContentLoadedEventEnd
perfEntries[0].loadEventStart
perfEntries[0].loadEventEnd