Slide 1

Slide 1 text

web apis you didn’t know existed probably @zenorocha

Slide 2

Slide 2 text

2008

Slide 3

Slide 3 text

2008

Slide 4

Slide 4 text

2009

Slide 5

Slide 5 text

2009

Slide 6

Slide 6 text

2010

Slide 7

Slide 7 text

2010

Slide 8

Slide 8 text

2011

Slide 9

Slide 9 text

2011

Slide 10

Slide 10 text

2012

Slide 11

Slide 11 text

2012

Slide 12

Slide 12 text

2013

Slide 13

Slide 13 text

2013

Slide 14

Slide 14 text

2014

Slide 15

Slide 15 text

2014

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

canvas svg geolocation local storage web sockets audio video drag & drop web rtc

Slide 18

Slide 18 text

page visibility

Slide 19

Slide 19 text

Provides an API to ask whether the current page is visible or not. page visibility

Slide 20

Slide 20 text

window.addEventListener('visibilitychange', () => { if (document.hidden) { console.log('Tab is hidden'); } else { console.log('Tab is focused'); } }); page visibility

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

window.addEventListener('visibilitychange', () => { switch(document.visibilityState) { case 'prerender': console.log('Tab is pre-rendering'); break; case 'hidden': console.log('Tab is hidden'); break; case 'visible': console.log('Tab is focused'); break; } });

Slide 23

Slide 23 text

caniuse.com/#feat=pagevisibility BROWSER support

Slide 24

Slide 24 text

where to use it?

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

state online

Slide 27

Slide 27 text

Exposes a network connection availability information to the web. online state

Slide 28

Slide 28 text

console.log(navigator.onLine ? 'online' : 'offline') online state

Slide 29

Slide 29 text

window.addEventListener('offline', networkStatus); window.addEventListener('online', networkStatus); function networkStatus(e) { console.log(e.type); } online state

Slide 30

Slide 30 text

caniuse.com/#feat=online-status BROWSER support

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

where to use it?

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

VIBRATION

Slide 35

Slide 35 text

Provides access to a form of tactile feedback. vibration

Slide 36

Slide 36 text

// Vibrate for 1 second navigator.vibrate(1000); // Vibrate with a pattern navigator.vibrate([400, 300, 300, 200, 500]); // Turn off vibration navigator.vibrate(0); VIBRATION vibrate wait vibrate wait vibrate

Slide 37

Slide 37 text

// Super Mario navigator.vibrate([125,75,125,275,200,275,125,75,125,27 5,200,600,200,600]); // Star Wars navigator.vibrate([500,110,500,110,450,110,200,110,170, 40,450,110,200,110,170,40,500]); // Go Go Power Rangers navigator.vibrate([150,150,150,150,75,75,150,150,150,15 0,450]); VIBRATION https://goo.gl/bX4ZQv

Slide 38

Slide 38 text

caniuse.com/#feat=vibration BROWSER support

Slide 39

Slide 39 text

where to use it?

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

DEVICE orientation

Slide 43

Slide 43 text

Provides access to device's physical orientation. device orientation

Slide 44

Slide 44 text

device orientation window.addEventListener('deviceorientation', (e) => { console.log(‘Gamma:’, e.gamma); console.log(‘Beta:’, e.beta); console.log(‘Alpha:’, e.alpha); });

Slide 45

Slide 45 text

device orientation let logo = document.querySelector(‘img'); window.addEventListener('deviceorientation', (e) => { let tiltLR = e.gamma; let tiltFB = e.beta; logo.style.transform = `rotate(${tiltLR}deg) rotate3d(1,0,0, ${tiltFB * -1}deg)`; });

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

caniuse.com/#feat=deviceorientation BROWSER support

Slide 48

Slide 48 text

where to use it?

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

clipboard copy & paste

Slide 51

Slide 51 text

Standard APIs for interacting with the clipboard (copy/cut/paste). clipboard

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

// 1. User interaction is required let button = document.querySelector('button'); button.addEventListener('click', () => { select(); copy(); }); clipboard

Slide 54

Slide 54 text

// 2. Programmatically select an element function select() { let input = document.querySelector('input'); input.focus(); input.setSelectionRange(0, input.value.length); } clipboard

Slide 55

Slide 55 text

// 3. Copy selected element text function copy() { try { document.execCommand('copy'); } catch (err) { console.error(err); } } clipboard

Slide 56

Slide 56 text

document.addEventListener('copy', (e) => { console.log(e.target.value); }); document.addEventListener('cut', (e) => { console.log(e.target.value); }); document.addEventListener('paste', (e) => { console.log(e.clipboardData.getData('text/plain')); }); clipboard

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

caniuse.com/#feat=clipboard BROWSER support

Slide 60

Slide 60 text

where to use it?

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

light ambient

Slide 64

Slide 64 text

Exposes sensor data that captures the light intensity. ambient light

Slide 65

Slide 65 text

window.addEventListener('devicelight', (e) => { console.log(`${e.value} lux`); }); ambient light

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

let sensor = new AmbientLightSensor(); sensor.start(); sensor.onchange = (e) => { console.log(e.reading.illuminance); }; sensor.stop(); ambient light sensor

Slide 69

Slide 69 text

BROWSER caniuse.com/#feat=ambient-light support

Slide 70

Slide 70 text

where to use it?

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

STATUS battery

Slide 74

Slide 74 text

Allows a web page to access battery information from desktop and mobile devices. battery status

Slide 75

Slide 75 text

navigator.getBattery().then((battery) => { console.log(`${battery.level * 100}%`); battery.addEventListener('levelchange', () => { console.log(`${this.level * 100}%`); }); }); battery status

Slide 76

Slide 76 text

caniuse.com/#feat=battery-status BROWSER support

Slide 77

Slide 77 text

where to use it?

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

web components templates custom elements shadow dom html imports

Slide 81

Slide 81 text

progressive web apps service workers push notifications offline support app manifest background sync

Slide 82

Slide 82 text

WEB assembly

Slide 83

Slide 83 text

WebAssembly, or wasm, is a low-level programming language for the client-side. web assembly

Slide 84

Slide 84 text

under developm ent BROWSER support

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

WEBVR

Slide 87

Slide 87 text

Experimental API that provides access to Virtual Reality devices, such as the Oculus Rift or Google Cardboard. web VR

Slide 88

Slide 88 text

BROWSER support chromestatus.com/features#webvr

Slide 89

Slide 89 text

No content

Slide 90

Slide 90 text

gamepad

Slide 91

Slide 91 text

Gives access to a game controller via USB. gamepad

Slide 92

Slide 92 text

window.addEventListener('gamepadconnected', () => { let gp = navigator.getGamepads()[0]; console.log(‘ID:’, gp.id); console.log(‘Axes:’, gp.axes.length); console.log(‘Buttons:’, gp.buttons.length); }); gamepad

Slide 93

Slide 93 text

window.addEventListener('gamepadconnected', gameLoop); function gameLoop() { let gp = navigator.getGamepads()[0]; if (gp.buttons[0].pressed) { console.log('X'); } requestAnimationFrame(gameLoop); } game loop

Slide 94

Slide 94 text

No content

Slide 95

Slide 95 text

caniuse.com/#feat=gamepad BROWSER support

Slide 96

Slide 96 text

No content

Slide 97

Slide 97 text

No content

Slide 98

Slide 98 text

thank you @zenorocha so much