SlideShare a Scribd company logo
web apis
you
didn’t know
existed
probably
@zenorocha
2008
2008
2009
2009
2010
2010
2011
2011
2012
2012
2013
2013
2014
2014
Web APIs you (probably) didn't know existed
canvassvg
geolocation
local
storage
web
sockets
audio
video
drag &
drop
web rtc
page
visibility
Provides an API to ask
whether the current page
is visible or not.
page visibility
window.addEventListener('visibilitychange', () => {
if (document.hidden) {
console.log('Tab is hidden');
}
else {
console.log('Tab is focused');
}
});
page visibility
Web APIs you (probably) didn't know existed
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;
}
});
caniuse.com/#feat=pagevisibility
BROWSER
support
where
to use it?
Web APIs you (probably) didn't know existed
state
online
Exposes a network
connection availability
information to the web.
online state
console.log(navigator.onLine ? 'online' : 'offline')
online state
window.addEventListener('offline', networkStatus);
window.addEventListener('online', networkStatus);
function networkStatus(e) {
console.log(e.type);
}
online state
caniuse.com/#feat=online-status
BROWSER
support
Web APIs you (probably) didn't know existed
where
to use it?
Web APIs you (probably) didn't know existed
VIBRATION
Provides access to a
form of tactile feedback.
vibration
// 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
// 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
caniuse.com/#feat=vibration
BROWSER
support
where
to use it?
Web APIs you (probably) didn't know existed
Web APIs you (probably) didn't know existed
DEVICE
orientation
Provides access to device's
physical orientation.
device orientation
device orientation
window.addEventListener('deviceorientation', (e) => {
console.log(‘Gamma:’, e.gamma);
console.log(‘Beta:’, e.beta);
console.log(‘Alpha:’, e.alpha);
});
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)`;
});
Web APIs you (probably) didn't know existed
caniuse.com/#feat=deviceorientation
BROWSER
support
where
to use it?
Web APIs you (probably) didn't know existed
clipboard
copy&paste
Standard APIs for
interacting with the
clipboard (copy/cut/paste).
clipboard
Web APIs you (probably) didn't know existed
// 1. User interaction is required
let button = document.querySelector('button');
button.addEventListener('click', () => {
select();
copy();
});
clipboard
// 2. Programmatically select an element
function select() {
let input = document.querySelector('input');
input.focus();
input.setSelectionRange(0, input.value.length);
}
clipboard
// 3. Copy selected element text
function copy() {
try {
document.execCommand('copy');
}
catch (err) {
console.error(err);
}
}
clipboard
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
Web APIs you (probably) didn't know existed
Web APIs you (probably) didn't know existed
caniuse.com/#feat=clipboard
BROWSER
support
where
to use it?
Web APIs you (probably) didn't know existed
Web APIs you (probably) didn't know existed
light
ambient
Exposes sensor data that
captures the light intensity.
ambient light
window.addEventListener('devicelight', (e) => {
console.log(`${e.value} lux`);
});
ambient light
Web APIs you (probably) didn't know existed
Web APIs you (probably) didn't know existed
let sensor = new AmbientLightSensor();
sensor.start();
sensor.onchange = (e) => {
console.log(e.reading.illuminance);
};
sensor.stop();
ambient light sensor
BROWSER
caniuse.com/#feat=ambient-light
support
where
to use it?
Web APIs you (probably) didn't know existed
Web APIs you (probably) didn't know existed
STATUS
battery
Allows a web page to access
battery information from
desktop and mobile devices.
battery status
navigator.getBattery().then((battery) => {
console.log(`${battery.level * 100}%`);
battery.addEventListener('levelchange', () => {
console.log(`${this.level * 100}%`);
});
});
battery status
caniuse.com/#feat=battery-status
BROWSER
support
where
to use it?
Web APIs you (probably) didn't know existed
Web APIs you (probably) didn't know existed
web
components
templates
custom elements
shadow dom
html imports
progressive
web apps
service workers
push notifications
offline support
app manifest
background sync
WEBassembly
WebAssembly, or wasm,
is a low-level programming
language for the client-side.
web assembly
underdevelopm
ent
BROWSER
support
Web APIs you (probably) didn't know existed
WEBVR
Experimental API that
provides access to Virtual
Reality devices, such as the
Oculus Rift or Google
Cardboard.
web VR
BROWSER
support
chromestatus.com/features#webvr
Web APIs you (probably) didn't know existed
gamepad
Gives access to a game
controller via USB.
gamepad
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
window.addEventListener('gamepadconnected', gameLoop);
function gameLoop() {
let gp = navigator.getGamepads()[0];
if (gp.buttons[0].pressed) {
console.log('X');
}
requestAnimationFrame(gameLoop);
}
game loop
Web APIs you (probably) didn't know existed
caniuse.com/#feat=gamepad
BROWSER
support
Web APIs you (probably) didn't know existed
Web APIs you (probably) didn't know existed
thank you
@zenorocha
so much

More Related Content

PDF
Javascript is your (Auto)mate
PDF
Ember background basics
PDF
Ember: Guts & Goals
KEY
Sprout core and performance
PDF
Cheap frontend tricks
PDF
How Kris Writes Symfony Apps
PDF
Drupal, meet Assetic
PDF
HTML5勉強会#23_GeoHex
Javascript is your (Auto)mate
Ember background basics
Ember: Guts & Goals
Sprout core and performance
Cheap frontend tricks
How Kris Writes Symfony Apps
Drupal, meet Assetic
HTML5勉強会#23_GeoHex

What's hot (20)

KEY
Loadrunner
PPTX
Spine.js
PDF
Avinash Kundaliya: Javascript and WordPress
KEY
Quality Use Of Plugin
PDF
Firefox OS learnings & visions, WebAPIs - budapest.mobile
PPTX
18.register login
PDF
Introduction to AngularJS
PDF
How to actually use promises - Jakob Mattsson, FishBrain
PDF
G* on GAE/J 挑戦編
PDF
Mojolicious
PDF
Clearance: Simple, complete Ruby web app authentication.
PDF
Puppet modules for Fun and Profit
PPTX
2. 엔티티 매핑(entity mapping) 2 2 엔티티매핑 2-2-4. 식별자 자동 생성(@generated-value)3
PDF
YUI on the go
PDF
Plugin jQuery, Design Patterns
PDF
Automating Front-End Workflow
PDF
Building Large jQuery Applications
PDF
How Kris Writes Symfony Apps
PPTX
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
KEY
jQuery Plugin Creation
Loadrunner
Spine.js
Avinash Kundaliya: Javascript and WordPress
Quality Use Of Plugin
Firefox OS learnings & visions, WebAPIs - budapest.mobile
18.register login
Introduction to AngularJS
How to actually use promises - Jakob Mattsson, FishBrain
G* on GAE/J 挑戦編
Mojolicious
Clearance: Simple, complete Ruby web app authentication.
Puppet modules for Fun and Profit
2. 엔티티 매핑(entity mapping) 2 2 엔티티매핑 2-2-4. 식별자 자동 생성(@generated-value)3
YUI on the go
Plugin jQuery, Design Patterns
Automating Front-End Workflow
Building Large jQuery Applications
How Kris Writes Symfony Apps
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
jQuery Plugin Creation
Ad

Viewers also liked (20)

PDF
Desbravando o HTML5 Boilerplate
PDF
Construindo Projetos Robustos em HTML5
PPT
HTML 5
PPTX
Wordpress
PDF
Web Components, A próxima revolução do desenvolvimento web.
PPT
Alabot
PDF
Getting started with YUI3 and AlloyUI
PPTX
Introdução ao HTML4 e HTML5
PDF
Como Perder Peso (no browser)
PDF
How to create high scalable JavaScript apps for Java Portals
PDF
WTF Javascript - FrontInRio 2011
KEY
Super Trunfo - Case de Dados Abertos
PDF
Javascript Orientado a Objetos - Fisl12
PDF
Augmented Reality in JavaScript
PDF
It's Javascript Time
PPT
Aula javascript
PDF
Um pequeno estudo sobre a microsoft
ODP
Javascript para adultos
PDF
Os mitos do desenvolvimento front-end
PDF
Future of Web Development
Desbravando o HTML5 Boilerplate
Construindo Projetos Robustos em HTML5
HTML 5
Wordpress
Web Components, A próxima revolução do desenvolvimento web.
Alabot
Getting started with YUI3 and AlloyUI
Introdução ao HTML4 e HTML5
Como Perder Peso (no browser)
How to create high scalable JavaScript apps for Java Portals
WTF Javascript - FrontInRio 2011
Super Trunfo - Case de Dados Abertos
Javascript Orientado a Objetos - Fisl12
Augmented Reality in JavaScript
It's Javascript Time
Aula javascript
Um pequeno estudo sobre a microsoft
Javascript para adultos
Os mitos do desenvolvimento front-end
Future of Web Development
Ad

Similar to Web APIs you (probably) didn't know existed (20)

PDF
WebAPIs & WebRTC - Spotify/sthlm.js
PDF
Mozilla, Firefox OS and the Open Web
PDF
Web APIs – expand what the Web can do
PPTX
Academy PRO: HTML5 API multimedia
PDF
Firefox OS Introduction at Bontouch
PDF
Firefox OS, the Open Web & WebAPIs - Geek Meet Västerås
PDF
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - SpainJS
PDF
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - BrazilJS
PDF
Firefox OS, the Open Web & WebAPIs - HTML5DevConf, San Francisco
PPTX
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
PDF
Frontend. Global domination.
PDF
Front-end. Global domination
PDF
HTML5 JS APIs
PDF
Bringing the Open Web & APIs to 
mobile devices with Firefox OS, JSFoo, India
PPTX
Firefox OS Web APIs, taking it to the next level
PDF
Web APIs - Mobiletech Conference 2015
PDF
Firefox OS workshop, JSFoo, India
PDF
WebRTC & Firefox OS - presentation at Google
PDF
Firefox OS, HTML5 to the next level - Python Montreal - 2014-05-12
PDF
Firefox OS, fixing the mobile web - FITC Toronto - 2014-04-28
WebAPIs & WebRTC - Spotify/sthlm.js
Mozilla, Firefox OS and the Open Web
Web APIs – expand what the Web can do
Academy PRO: HTML5 API multimedia
Firefox OS Introduction at Bontouch
Firefox OS, the Open Web & WebAPIs - Geek Meet Västerås
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - SpainJS
Bringing the Open Web & APIs to 
mobile devices with Firefox OS - BrazilJS
Firefox OS, the Open Web & WebAPIs - HTML5DevConf, San Francisco
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
Frontend. Global domination.
Front-end. Global domination
HTML5 JS APIs
Bringing the Open Web & APIs to 
mobile devices with Firefox OS, JSFoo, India
Firefox OS Web APIs, taking it to the next level
Web APIs - Mobiletech Conference 2015
Firefox OS workshop, JSFoo, India
WebRTC & Firefox OS - presentation at Google
Firefox OS, HTML5 to the next level - Python Montreal - 2014-05-12
Firefox OS, fixing the mobile web - FITC Toronto - 2014-04-28

Recently uploaded (20)

PPTX
sap open course for s4hana steps from ECC to s4
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Encapsulation theory and applications.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Spectroscopy.pptx food analysis technology
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Machine learning based COVID-19 study performance prediction
sap open course for s4hana steps from ECC to s4
Chapter 3 Spatial Domain Image Processing.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Building Integrated photovoltaic BIPV_UPV.pdf
Review of recent advances in non-invasive hemoglobin estimation
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Electronic commerce courselecture one. Pdf
Encapsulation_ Review paper, used for researhc scholars
Encapsulation theory and applications.pdf
Big Data Technologies - Introduction.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Spectroscopy.pptx food analysis technology
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
The AUB Centre for AI in Media Proposal.docx
Empathic Computing: Creating Shared Understanding
Per capita expenditure prediction using model stacking based on satellite ima...
Machine learning based COVID-19 study performance prediction

Web APIs you (probably) didn't know existed