Project Fugu
Project Fugu
By Lucien Immink
8 min read
Cross-platform software development is hard. Each platform has its specific implementation of an API and you end up with separate apps for each platform. Multiple frameworks try to fix this issue by creating an abstract between the platform and the application. Browser vendors are doing the same and it's called Project Fugu.
- Authors
- Name
- Lucien Immink
- linkedinLucien Immink
- twitter@lucienimmink
- Github
- githublucienimmink
Cross-platform software development is hard. Features and capabilities of an application require you to think about how it needs to be implemented on different platforms like Android, iOS, Web, Windows, MacOS and Linux. If you, for example, need to access the address details of a contact that is stored on a device you need to implement a piece of software, that allows you to access and choose a contact, let's call it a contact picker, for all the different platforms you want to support or you need to come up with a completely custom implementation. Custom implementations are probably not what you want to do. It can become quite messy quite fast.
So what can you do?
What about an abstraction layer between the OS native API and a common top layer, which is preferably written in a well-known set of languages that can handle UIs with a breeze, like HTML, CSS and JavaScript? Here we are describing a framework like Apache Cordova, Ionic's Capacitor, Electron or Tauri. These hybrid applications combine web languages with a wrapper for the OS native APIs. Hybrid cause they use web technology packaged as apps for distribution and have access to native device APIs.
While these hybrid frameworks enable developers to build one UI for multiple platforms they still have to build the application for all the platforms they want to support. The support for a platform or platform specific feature can often be flaky.
But what about the web platform itself? Progressive Web Apps (PWAs) bring offline support and app-like experiences to the web. Extending the PWA principle with APIs to include more native APIs while keeping the principles of the web (trust, privacy and security) is the core of Project Fugu π‘.
Project Fugu
Project Fugu π‘ is an effort to close gaps in the web's capabilities enabling new classes of applications to run on the web. APIs that Project Fugu is delivering enable new experiences on the web while preserving the web's core benefits of security, low friction, and cross-platform delivery. All Project Fugu API proposals are made in the open and on the standards track.
Fugu is organized as a Chromium project, open to all Chromium contributors and organizations. Today, that includes Microsoft, Intel, Samsung, Electron and Google (among others). Fugu Leads triage incoming requests from partners, determine demand, prioritize them, find champions, track development, and help organize the release and documentation for the capability.
Let's take a look at some of the features that have already been released:
Async Clipboard access
The original clipboard API is synchronized, meaning that it blocks access to the JavaScript thread as long as it is active. This is ok for handling small amounts of data like a single line of plain text but it would be a bad user experience for larger chunks of data like an image or a video. Another downside is that it could only read and write to the DOM. Project Fugu introduced async clipboard access. The async clipboard API is based on a well-defined permission model that doesn't block the page.
Writing text to the clipboard
To copy text to the clipboard call writeText()
. Since this API is asynchronous, the writeText()
function returns a Promise that resolves or rejects depending on whether the passed text is copied successfully:
async function copyPageUrl() {
try {
await navigator.clipboard.writeText(location.href)
} catch (err) {
console.error('Failed to copy: ', err)
}
}
Support for writeText()
clipboard has been added since Chrome 66, Firefox 63, Edge 79 and Safari 13.1 and thus is widely available on all platforms and browsers.
Writing data to the clipboard
To copy raw data to the clipboard the data needs to be a blob
meaning that all forms of data that are available as a blob
can be copied to the clipboard, including canvas and images/video (using fetch).
try {
const imgURL = '/images/generic/file.png'
await navigator.clipboard.write([
new ClipboardItem({
// Set the mimetype beforehand and write a promise as the value.
'image/png': await fetch(imgUrl)?.blob(),
}),
])
console.log('Image copied.')
} catch (err) {
console.error(err.name, err.message)
}
Support for write()
clipboard has been added since Chrome 66, Firefox 63 (only desktop), Edge 79 and Safari 13.1 and thus is widely available on most platforms and browsers.
Reading from the clipboard
The navigator.clipboard.read()
method is also asynchronous and returns a promise. To read an image from the clipboard, obtain a list of ClipboardItem
objects, then iterate over them.
Each ClipboardItem
can hold its contents in different types, so you'll need to iterate over the list of types, again using a for...of
loop. For each type, call the getType()
method with the current type as an argument to obtain the corresponding blob. As before, this code is not tied to images and will work with other future file types.
async function getClipboardContents() {
try {
const clipboardItems = await navigator.clipboard.read()
for (const clipboardItem of clipboardItems) {
for (const type of clipboardItem.types) {
const blob = await clipboardItem.getType(type)
console.log(URL.createObjectURL(blob))
}
}
} catch (err) {
console.error(err.name, err.message)
}
}
Support for read()
clipboard has been added since Chrome 86, Firefox 90 (only desktop), Edge 79 and Safari 13.1 and thus is widely available on most platforms and browsers.
Badging API
The Badging API gives web developers a method of setting a badge on a document or application, to act as a notification that the state has changed without displaying a more distracting notification. A common use case for this would be an application with a messaging feature displaying a badge on the app icon to show that new messages have arrived.
Types of badges
There are two types of badges:
- Document badges are typically shown in the browser tab near or on the page icon.
- App badges, which are associated with the icon of an installed web app. These may display on the app icon in the dock, shelf, or home screen depending on the device in use.
Badge states
nothing
: Indicating that no badge is currently set. A badge can be in this state due to it being cleared by the application, or being reset by the user agent.flag
: Indicating that the badge is set, but has no specific data to display. A badge will be in this state if the application has set a badge, but has not passed any value to the method.<int>
: A value passed when setting the badge. This value will never be 0, passing a value of 0 when setting a badge will cause the user agent to clear the badge by setting it tonothing
.
navigator.setClientBadge() // set a badge
navigator.clearClientBadge() // clear the badge
navigator.setAppBadge(12) // set 12 as app badge
WebOTP API
These days, most people in the world own a mobile device and developers are commonly using phone numbers as an identifier for users of their services.
There are a variety of ways to verify phone numbers, but a randomly generated one-time password (OTP) sent by SMS is one of the most common. Sending this code back to the developer's server demonstrates control of the phone number.
The WebOTP API lets your app receive specially-formatted messages bound to your app's domain. From this, you can programmatically obtain an OTP from an SMS message and verify a phone number for the user more easily.
<form>
<input autocomplete="one-time-code" required />
<input type="submit" />
</form>
if ('OTPCredential' in window) {
window.addEventListener('DOMContentLoaded', e => {
...
const ac = new AbortController();
const input = document.querySelector('input[autocomplete="one-time-code"]');
navigator.credentials.get({
otp: { transport:['sms'] },
signal: ac.signal
}).then(otp => {
input.value = otp.code;
}).catch(err => { /* ... */ });
});
}
Learn more about how to implement webOTP: https://developer.chrome.com/articles/web-otp/.
Support for webOTP has been added since Chrome 93, Edge 93. Firefox and Safari have no support, meaning that webOTP is not readily available yet.
File System Access
Dave Bitter has written an excellent article about File system access
Features in the pipeline
Some of the features that are being developed or considered at the moment:
- Changing system settings API
- Geofencing
- Splash screen
- Remote desktop control
- Call dialer/answering/control
...but what about the other one?
Project Fugu can offer a great experience, but only if the browser supports these APIs. Safari (and thus iOS and iPad OS) are not actively part of Project Fugu and have been slow with implementing APIs that extend the functionality of the web. Eg. support for service workers and push notifications. If Safari and Apple will ever actively contribute to Project Fugu, remains an open question. On the one hand, the fact that Apple does not allow other browser engines from their mobile platforms is one of the main reasons why web apps are still considered less than native apps. On the other, EU regulators have noticed this as well and are actively in debate if this 'browser ban' is considered to be legal. For more information concerning this specific topic, check out open-web-advocacy.
Closing thoughts
Cross-platform software development is hard. Features and capabilities of an application require you to think about how it needs to be implemented on different platforms like Android, iOS, Web, Windows, MacOS and Linux. If you, for example, need to access the address details of a contact that is stored on a device you need to implement a piece of software, that allows you to access and choose a contact, let's call it a contact picker, for all the different platforms you want to support or you need to come up with a completely custom implementation. Custom implementations are probably not what you want to do. It can become quite messy quite fast.
So what can you do?
Progressive Web Apps (PWAs) bring offline support and app-like experiences to the web. Extending the PWA principle with APIs to include more native APIs while keeping the principles of the web (trust, privacy and security) is the core of Project Fugu π‘.
Some of these APIs are readily available and should be considered when that feature is needed, like for example the async clipboard API. Other APIs though are only available in certain browsers, like the webOTP API so handle them with care and consult the online references.
If Safari and Apple will ever actively contribute to Project Fugu, remains an open question. On the one hand, the fact that Apple does not allow other browser engines from their mobile platforms is one of the main reasons why web apps are still considered less than native apps. On the other, EU regulators have noticed this as well and are actively in debate if this 'browser ban' is considered to be legal. For more information concerning this specific topic, check out open-web-advocacy.
Upcoming events
Drupal CMS Launch Party
Zoals sommigen misschien weten wordt op 15 Januari een nieuwe distributie van Drupal gelanceerd. Namelijk Drupal CMS (ook wel bekend als Starshot). Om dit te vieren gaan we op onze campus een klein eventje organiseren. We gaan die dag samen de livestream volgen waarbij het product gelanceerd wordt. De agenda is als volgt: 17u β 18u30: Drupal CMS livestream met taart 18u30 β 19u00: Versteld staan van de functionaliteiten 19u β 20u: Pizza eten en verder versteld staan van de functionaliteiten Laat ons zeker weten of je komt of niet door de invite te accepteren! Tot dan!
| Coven of Wisdom Herentals
Go to page for Drupal CMS Launch PartyCoven of Wisdom - Herentals - Winter `24 edition
Worstelen jij en je team met het bouwen van schaalbare digitale ecosystemen of zit je vast in een props hell met React of in een ander framework? Kom naar onze meetup waar ervaren sprekers hun inzichten en ervaringen delen over het bouwen van robuuste en flexibele applicaties. Schrijf je in voor een avond vol kennis, heerlijk eten en een mix van creativiteit en technologie! π 18:00 β πͺ Deuren open 18:15 β π Food & drinks 19:00 β π’ Building a Mature Digital Ecosystem - Maarten Heip 20:00 β πΉ Kleine pauze 20:15 β π’ Compound Components: A Better Way to Build React Components - Sead Memic 21:00 β πββοΈ Drinks 22:00 β π» Tot de volgende keer? Tijdens deze meetup gaan we dieper in op het bouwen van digitale ecosystemen en het creΓ«ren van herbruikbare React componenten. Maarten deelt zijn expertise over het ontwikkelen van een volwassen digitale infrastructuur, terwijl Sead je laat zien hoe je 'From Props Hell to Component Heaven' kunt gaan door het gebruik van Compound Components. Ze delen praktische inzichten die je direct kunt toepassen in je eigen projecten. π Waar? Je vindt ons bij iO Herentals - Zavelheide 15, Herentals. Volg bij aankomst de borden 'meetup' vanaf de receptie. π« Schrijf je in! De plaatsen zijn beperkt, dus RSVP is noodzakelijk. Dit helpt ons ook om de juiste hoeveelheid eten en drinken te voorzien - we willen natuurlijk niet dat iemand met een lege maag naar huis gaat! π Over iO Wij zijn iO: een groeiend team van experts die end-to-end-diensten aanbieden voor communicatie en digitale transformatie. We denken groot en werken lokaal. Aan strategie, creatie, content, marketing en technologie. In nauwe samenwerking met onze klanten om hun merken te versterken, hun digitale systemen te verbeteren en hun toekomstbestendige groei veilig te stellen. We helpen klanten niet alleen hun zakelijke doelen te bereiken. Samen verkennen en benutten we de eindeloze mogelijkheden die markten in constante verandering bieden. De springplank voor die visie is talent. Onze campus is onze broedplaats voor innovatie, die een omgeving creΓ«ert die talent de ruimte en stimulans geeft die het nodig heeft om te ontkiemen, te ontwikkelen en te floreren. Want werken aan de infinite opportunities van morgen, dat doen we vandaag.
| Coven of Wisdom Herentals
Go to page for Coven of Wisdom - Herentals - Winter `24 editionThe Test Automation Meetup
PLEASE RSVP SO THAT WE KNOW HOW MUCH FOOD WE WILL NEED Test automation is a cornerstone of effective software development. It's about creating robust, predictable test suites that enhance quality and reliability. By diving into automation, you're architecting systems that ensure consistency and catch issues early. This expertise not only improves the development process but also broadens your skillset, making you a more versatile team member. Whether you're a developer looking to enhance your testing skills or a QA professional aiming to dive deeper into automation, RSVP for an evening of learning, delicious food, and the fusion of coding and quality assurance! ππ 18:00 β πͺ Doors open to the public 18:15 β π Letβs eat 19:00 β π’ First round of Talks 19:45 β πΉ Small break 20:00 β π’ Second round of Talks 20:45 β π» Drinks 21:00 β πββοΈ See you next time? First Round of Talks: The Power of Cross-browser Component Testing - Clarke Verdel, SR. Front-end Developer at iO How can you use Component Testing to ensure consistency cross-browser? Overcoming challenges in Visual Regression Testing - Sander van Surksum, Pagespeed | Web Performance Consultant and Sannie Kwakman, Freelance Full-stack Developer How can you overcome the challenges when setting up Visual Regression Testing? Second Round of Talks: Omg who wrote this **** code!? - Erwin Heitzman, SR. Test Automation Engineer at Rabobank How can tests help you and your team? Beyond the Unit Test - Christian WΓΌrthner, SR. Android Developer at iO How can you do advanced automated testing for, for instance, biometrics? RSVP now to secure your spot, and let's explore the fascinating world of test automation together!
| Coven of Wisdom - Amsterdam
Go to page for The Test Automation Meetup