<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Luiz Schons – Studying out of curiosity</title><link>https://luizschons.com/series/studying-out-of-curiosity/</link><description>Recent content in Studying out of curiosity on Luiz Schons</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Tue, 03 Nov 2026 00:00:00 -0300</lastBuildDate><atom:link href="https://luizschons.com/series/studying-out-of-curiosity/index.xml" rel="self" type="application/rss+xml"/><item><title>Programming is still fun: the joy of building things in the AI era</title><link>https://luizschons.com/posts/personal-projects-as-a-lab/</link><pubDate>Tue, 03 Nov 2026 00:00:00 -0300</pubDate><guid>https://luizschons.com/posts/personal-projects-as-a-lab/</guid><description>
&lt;p&gt;It&amp;rsquo;s been a long time since I had this much fun programming. Really. Those ideas that sat on the shelf for years, the &amp;ldquo;someday I&amp;rsquo;d like to understand how that works&amp;rdquo; kind, now turn into something that runs in a single evening. And along the way I end up learning a lot, almost without noticing.&lt;/p&gt;
&lt;p&gt;This isn&amp;rsquo;t a tutorial. It&amp;rsquo;s more of an excited account from someone who rediscovered the joy of &lt;strong&gt;building things just because&lt;/strong&gt;, and of how that became my favorite way to study.&lt;/p&gt;
&lt;h2 data-hextra-search-id="work-teaches-a-lot-too"&gt;Work teaches a lot, too&lt;span class="hx:absolute hx:-mt-20" id="work-teaches-a-lot-too"&gt;&lt;/span&gt;
&lt;a href="#work-teaches-a-lot-too" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;First things first: I learn a lot at work. That&amp;rsquo;s where the real problems show up, with real users, production, deadlines and a whole team reviewing what I do. A lot of what I know today came from a bug in production or a really thorough code review. The &lt;a href="https://luizschons.com/series/ai-friendly-architecture/"&gt;series on AI-friendly architecture&lt;/a&gt; I wrote here on the blog grew directly out of that.&lt;/p&gt;
&lt;p&gt;But work has its own way of teaching. The problem is handed to me, the stack is the team&amp;rsquo;s, and it makes total sense to choose the safest path. I learn what the problem asks for.&lt;/p&gt;
&lt;p&gt;In a personal project, the logic flips. I pick the question. The stack is the one that made me curious. And if everything goes wrong, that&amp;rsquo;s fine: the mistakes are part of the fun. It&amp;rsquo;s not a better or worse way to learn; it&amp;rsquo;s &lt;strong&gt;a different way&lt;/strong&gt;, looser and more playful. And the two complement each other: what I discover while playing comes back to work, and what work teaches me makes the play more ambitious.&lt;/p&gt;
&lt;h2 data-hextra-search-id="building-got-easy-and-thats-great"&gt;Building got easy, and that&amp;rsquo;s great&lt;span class="hx:absolute hx:-mt-20" id="building-got-easy-and-thats-great"&gt;&lt;/span&gt;
&lt;a href="#building-got-easy-and-thats-great" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;For a long time, what killed my ideas wasn&amp;rsquo;t the hard part. It was the boring part. To reach the question I cared about, I needed setup, build, UI, CSS, deploy&amp;hellip; and many ideas died in boilerplate (that repetitive code every project needs and nobody wants to write).&lt;/p&gt;
&lt;p&gt;Today an AI agent (an assistant that reads code, writes it, runs commands and fixes what went wrong) handles a good part of that. The skeleton is ready in one evening, and all the time left over goes to the part I always enjoyed: understanding how the thing works underneath.&lt;/p&gt;
&lt;p&gt;Some people feel AI took the fun out of programming. For me it was the opposite. It took away the part that made me give up and left the part that made me start.&lt;/p&gt;
&lt;h2 data-hextra-search-id="building-is-studying-too"&gt;Building is studying too&lt;span class="hx:absolute hx:-mt-20" id="building-is-studying-too"&gt;&lt;/span&gt;
&lt;a href="#building-is-studying-too" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;When you build something out of curiosity, the questions show up on their own. You don&amp;rsquo;t read about WebRTC because it&amp;rsquo;s on a syllabus; you read about it because your game won&amp;rsquo;t connect over 4G and you want to know why. That kind of question sticks in your head in a way no course can match.&lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s one catch, though. If I let the agent do everything, I end up with a working project and no idea how it works. In January 2026, Anthropic published an &lt;a href="https://www.anthropic.com/research/AI-assistance-coding-skills" target="_blank" rel="noopener"&gt;experiment&lt;/a&gt; with developers learning a new Python library: those who only asked the AI for code did worse on the quiz about the concepts, especially on debugging. Those who used AI to &lt;strong&gt;ask questions and request explanations&lt;/strong&gt; still learned the material (&lt;a href="https://arxiv.org/abs/2601.20245" target="_blank" rel="noopener"&gt;full paper&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;So I follow a simple rule:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;I let the agent do what I already know how to do. What I want to learn, I do by hand or read line by line.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In practice, the agent builds the UI and the deploy workflow. When I reach the piece that made me curious, I slow down: I ask &amp;ldquo;why this way?&amp;rdquo; until it makes sense, I break it on purpose to watch the error happen, I read the spec and, at the end, I write about what I learned. Writing is the best test of &amp;ldquo;did I really get it?&amp;rdquo;.&lt;/p&gt;
&lt;h2 data-hextra-search-id="things-i-built-just-because"&gt;Things I built just because&lt;span class="hx:absolute hx:-mt-20" id="things-i-built-just-because"&gt;&lt;/span&gt;
&lt;a href="#things-i-built-just-because" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;This blog.&lt;/strong&gt; I wanted to know how close a static site, which is just a bunch of HTML files with no server at all, could get to behaving like a living system. It&amp;rsquo;s generated by &lt;a href="https://gohugo.io/" target="_blank" rel="noopener"&gt;Hugo&lt;/a&gt;, a static site generator, and hosted for free on GitHub Pages. Every morning, a GitHub Actions workflow runs on its own: it fetches my talks from the public API of &lt;a href="https://sessionize.com/" target="_blank" rel="noopener"&gt;Sessionize&lt;/a&gt;, the platform conferences use to manage speakers and sessions, rebuilds the site and publishes the posts scheduled for that day. After the deploy, a script drafts a &lt;a href="https://buttondown.com/" target="_blank" rel="noopener"&gt;Buttondown&lt;/a&gt; newsletter for each new post. No database, no server, and the site updates itself. The details are in &lt;a href="https://luizschons.com/posts/hugo-sessionize-cron-blog-setup/"&gt;Hugo, Sessionize and a cron&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://luizschons.com/posts/how-ito-works/"&gt;Ito&lt;/a&gt;.&lt;/strong&gt; A game you play with friends, each on their own phone, built &lt;strong&gt;peer-to-peer&lt;/strong&gt; (P2P): the phones talk directly to each other, with no game server in the middle. The idea came from FIFA (now EA Sports FC). In P2P matches, &lt;a href="https://www.ea.com/games/battlefield/news/pitch-notes-fifa20-game-data-center" target="_blank" rel="noopener"&gt;according to EA itself&lt;/a&gt;, one of the players becomes the host of the match. I wanted to understand how that works, and the questions kept coming: with no server, how do two phones find each other on the internet? And what stops one of them from cheating? A later post in the series covers what I found out.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A &lt;a href="https://luizschons.com/posts/how-web-push-works/"&gt;Web Push&lt;/a&gt; lab.&lt;/strong&gt; I was always intrigued by how a notification arrives with the tab closed. The lab turned into a PWA (a website you can install as an app), and it showed you can send notifications without paying for any notification service: the browser&amp;rsquo;s own push service delivers them at no cost, and the message is encrypted so that not even that service can read it. On the sender&amp;rsquo;s side, all you need is a small server and a pair of keys.&lt;/p&gt;
&lt;p&gt;None of these projects will change my job tomorrow. And that&amp;rsquo;s fine. They exist because I got curious, and each one taught me more than many tutorials ever did.&lt;/p&gt;
&lt;h2 data-hextra-search-id="if-you-want-to-try"&gt;If you want to try&lt;span class="hx:absolute hx:-mt-20" id="if-you-want-to-try"&gt;&lt;/span&gt;
&lt;a href="#if-you-want-to-try" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Start small, with just one curiosity.&lt;/strong&gt; A project you&amp;rsquo;ll actually use gives you a reason to finish; one new concept (not five) gives you a chance to really understand it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use AI to skip the boring part, not the fun part.&lt;/strong&gt; Ask for the skeleton, but keep the piece that made you curious.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Measure it by the fun.&lt;/strong&gt; The question isn&amp;rsquo;t &amp;ldquo;am I done?&amp;rdquo;. It&amp;rsquo;s &amp;ldquo;did I learn something I didn&amp;rsquo;t know?&amp;rdquo; and &amp;ldquo;did I have fun?&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tell someone.&lt;/strong&gt; A README, a post, a chat over coffee. Explaining closes the loop.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 data-hextra-search-id="wrapping-up"&gt;Wrapping up&lt;span class="hx:absolute hx:-mt-20" id="wrapping-up"&gt;&lt;/span&gt;
&lt;a href="#wrapping-up" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Chris Kiehl wrote a piece with a title I really like: &lt;a href="https://chriskiehl.com/article/it-is-still-ok-to-enjoy-programming" target="_blank" rel="noopener"&gt;It&amp;rsquo;s still OK to enjoy programming&lt;/a&gt;. I&amp;rsquo;d go further: there may never have been a better time to enjoy programming. Building got easy, and when building gets easy, there&amp;rsquo;s room left for curiosity.&lt;/p&gt;
&lt;p&gt;So here&amp;rsquo;s the question: &lt;strong&gt;what would you build today, just to find out how it works?&lt;/strong&gt; Tell me in the comments or on &lt;a href="https://www.linkedin.com/in/luiz-schons/" target="_blank" rel="noopener"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Hugo, Sessionize and a cron job: my blog setup</title><link>https://luizschons.com/posts/hugo-sessionize-cron-blog-setup/</link><pubDate>Wed, 07 Oct 2026 00:00:00 -0300</pubDate><guid>https://luizschons.com/posts/hugo-sessionize-cron-blog-setup/</guid><description>
&lt;p&gt;For a good while my blog lived on Hashnode, and it worked fine. The problem showed up when I started writing in both English and Portuguese: Hashnode has no real support for two languages, so I published every article twice, as if they were unrelated posts, with nothing linking one to the other.&lt;/p&gt;
&lt;p&gt;I mentioned this to &lt;a href="https://leocavalcante.dev" target="_blank" rel="noopener"&gt;Leo Cavalcante&lt;/a&gt;, and he introduced me to Hugo. Thank you, Leo: that conversation turned into the blog you are reading now.&lt;/p&gt;
&lt;p&gt;Hugo gave me a lot more flexibility. In this post I walk through how I put it all together: the two languages, the talks page that updates itself, the automatically generated preview images, and the deploy that runs every day without me touching anything.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Updated on October 8, 2026:&lt;/strong&gt; since then I added the translated older articles, a language notice, topics, &amp;ldquo;Keep reading&amp;rdquo;, comments and click tracking. It is all in the new sections below.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 data-hextra-search-id="one-place-for-both-languages"&gt;One place for both languages&lt;span class="hx:absolute hx:-mt-20" id="one-place-for-both-languages"&gt;&lt;/span&gt;
&lt;a href="#one-place-for-both-languages" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;In Hugo, each article is a text file in the repository, and the translation is just another file next to it. Hugo understands that both are the same article: the English version lives at &lt;a href="https://luizschons.com" target="_blank" rel="noopener"&gt;luizschons.com&lt;/a&gt;, the Portuguese one under &lt;code&gt;/pt-br/&lt;/code&gt;, and each links to the other.&lt;/p&gt;
&lt;p&gt;In practice, the articles folder looks like this:&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;content/posts/
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;├── agent-observability-with-opentelemetry.md # English
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;├── agent-observability-with-opentelemetry.pt-br.md # Portuguese
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;├── hash-tables.md # English
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;└── tabelas-hash.pt-br.md # Portuguese&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;What links the two versions is the &lt;code&gt;translationKey&lt;/code&gt; in the front matter, and in &lt;code&gt;hugo.toml&lt;/code&gt; you only need to declare the languages:&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-markdown" data-lang="markdown"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;---
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;title: &amp;#39;Agent Observability with OpenTelemetry&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;date: 2026-09-16
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;series: [&amp;#39;AI-Friendly Architecture&amp;#39;]
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;translationKey: agent-observability-with-opentelemetry
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;---&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-toml" data-lang="toml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;defaultContentLanguage&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;en&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;languages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;en&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;languageCode&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;en-us&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;weight&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;languages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;pt-br&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;languageCode&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;pt-br&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;weight&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;That solved what bothered me on Hashnode. One article, two versions, all in one place, and Google understands they are the same page in different languages. The look came from a theme called Hextra, which I kept adapting with my own layouts until it felt like mine.&lt;/p&gt;
&lt;p&gt;The file names do not have to match: &lt;code&gt;hash-tables.md&lt;/code&gt; and &lt;code&gt;tabelas-hash.pt-br.md&lt;/code&gt; are the same article because they share the same &lt;code&gt;translationKey&lt;/code&gt;. That way each language gets a URL that makes sense in it.&lt;/p&gt;
&lt;h3 data-hextra-search-id="a-notice-not-a-redirect"&gt;A notice, not a redirect&lt;span class="hx:absolute hx:-mt-20" id="a-notice-not-a-redirect"&gt;&lt;/span&gt;
&lt;a href="#a-notice-not-a-redirect" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;Plenty of people land on the &amp;ldquo;wrong&amp;rdquo; version for them, from Google or from a shared link. I did not want to redirect anyone automatically, because that confuses Google and annoys people who prefer the other language. Instead, when a translation exists, a small notice shows up at the bottom: &amp;ldquo;This page is also available in English&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;The notice only appears when the browser&amp;rsquo;s preferred language, between Portuguese and English, is the other version&amp;rsquo;s. If the visitor closes it or switches language from the menu, that is stored in the browser and it does not come back:&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-javascript" data-lang="javascript"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;langs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;languages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;l&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;l&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;// the top preference between the two languages the site has
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;top&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;langs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;l&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;l&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;pt&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;l&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;en&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;})[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;wants&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;pt-br&amp;#39;&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;top&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;pt&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;pt&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;wants&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;langSuggestDismissed&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="nx"&gt;box&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hidden&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h2 data-hextra-search-id="bringing-the-old-articles-along"&gt;Bringing the old articles along&lt;span class="hx:absolute hx:-mt-20" id="bringing-the-old-articles-along"&gt;&lt;/span&gt;
&lt;a href="#bringing-the-old-articles-along" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;The articles that came from Hashnode had three problems. Many existed only in Portuguese. Their URLs ended with a hash, like &lt;code&gt;quicksort-33f8e917ab6c&lt;/code&gt;. And code showed up as plain paragraphs, with no colors and manual line breaks.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Translations with the original date.&lt;/strong&gt; Every article that only existed in Portuguese got an English version with the &lt;strong&gt;same date&lt;/strong&gt; as the original. That way the translation lands in the right spot of the list, instead of looking like I published eleven articles in one day. Today every article exists in both languages.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Clean URLs without breaking links.&lt;/strong&gt; Renaming a file changes its URL, and anyone with the old link (Google included) would hit a 404. For each old address there is a fixed page in &lt;code&gt;static/&lt;/code&gt; that just redirects to the new one:&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-html" data-lang="html"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c"&gt;&amp;lt;!-- static/posts/quicksort-33f8e917ab6c/index.html --&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;link&lt;/span&gt; &lt;span class="na"&gt;rel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;canonical&amp;#34;&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;https://luizschons.com/pt-br/posts/quicksort/&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;meta&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;robots&amp;#34;&lt;/span&gt; &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;noindex&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;meta&lt;/span&gt; &lt;span class="na"&gt;http-equiv&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;refresh&amp;#34;&lt;/span&gt; &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;0; url=https://luizschons.com/pt-br/posts/quicksort/&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Hugo has &lt;code&gt;aliases&lt;/code&gt; in the front matter for this, but newer versions put the aliases of Portuguese pages under &lt;code&gt;/pt-br/&lt;/code&gt;, while the old links lived at the root. Fixed pages do not depend on the Hugo version.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Real code blocks.&lt;/strong&gt; The blocks that came in as &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; with &lt;code&gt;&amp;lt;br /&amp;gt;&lt;/code&gt; became code blocks tagged with their language. Hugo then colors the code at build time, with no JavaScript, and the theme adds the copy button. I also gave every image a description (&lt;code&gt;alt&lt;/code&gt;) and swapped the tables that were images for real tables, which now show up translated in the English version.&lt;/p&gt;
&lt;h2 data-hextra-search-id="talks-straight-from-sessionize"&gt;Talks straight from Sessionize&lt;span class="hx:absolute hx:-mt-20" id="talks-straight-from-sessionize"&gt;&lt;/span&gt;
&lt;a href="#talks-straight-from-sessionize" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;All my talks and the events I have spoken at or organized were already on &lt;a href="https://sessionize.com/sschonss/" target="_blank" rel="noopener"&gt;Sessionize&lt;/a&gt;. Keeping the same list on the blog would mean doing the work twice again, so the blog now reads the data from there.&lt;/p&gt;
&lt;p&gt;Sessionize has a public API that returns the profile, the talks and the events as JSON. The &lt;a href="https://luizschons.com/speakers/" target="_blank" rel="noopener"&gt;talks page&lt;/a&gt; uses that JSON twice: when the site is built, and again in the browser of whoever opens the page. In practice, I add an event on Sessionize and a few minutes later it shows up on the blog, split into upcoming and past.&lt;/p&gt;
&lt;p&gt;At build time, a script of a few lines saves the JSON into &lt;code&gt;data/&lt;/code&gt;, where Hugo sees it as &lt;code&gt;site.Data.sessionize&lt;/code&gt;:&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;https://sessionize.com/api/speaker/json/2n3e2etaad&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;OUTPUT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;data/sessionize.json&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;User-Agent&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;hugo-sessionize-sync/1.0&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;urlopen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;profile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;OUTPUT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;w&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;utf-8&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dump&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ensure_ascii&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;indent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The template splits events by their end date, compared with the build day:&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-go-html-template" data-lang="go-html-template"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$today&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;time&lt;/span&gt;&lt;span class="na"&gt;.AsTime&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;now&lt;/span&gt;&lt;span class="na"&gt;.Format&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;2006-01-02&amp;#34;&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;-}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;range&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;site&lt;/span&gt;&lt;span class="na"&gt;.Data.sessionize.events&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;-}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;ge&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;time&lt;/span&gt;&lt;span class="na"&gt;.AsTime&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="na"&gt;.eventEndDate&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="na"&gt;.Unix&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$today&lt;/span&gt;&lt;span class="na"&gt;.Unix&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;-}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$upcoming&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$upcoming&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;append&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="na"&gt;.&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;-}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;-}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$past&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$past&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;append&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="na"&gt;.&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;-}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;-}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;-}}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In the browser, the same JSON is fetched again. Sessionize allows CORS, so a plain &lt;code&gt;fetch&lt;/code&gt; is enough. If it fails, the page keeps the build version and shows a link to the profile:&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-javascript" data-lang="javascript"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;https://sessionize.com/api/speaker/json/2n3e2etaad&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;HTTP &amp;#39;&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// redraws events, talks, stats and photo
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fail&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// shows the notice with the profile link
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The profile photo follows the same idea. It comes from Sessionize on the home page, on the talks page, in the site icon and in the preview images: change it there, it changes here.&lt;/p&gt;
&lt;p&gt;And if Sessionize goes down? The page keeps showing the last saved version, with a link to my profile, and the photo falls back to a copy stored in the blog itself.&lt;/p&gt;
&lt;p&gt;The photo fallback is plain HTML, so it works even before JavaScript loads:&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-html" data-lang="html"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;https://cdn.sessionize.com/image/...&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="na"&gt;onerror&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;this.onerror=null;this.src=&amp;#39;/images/profile-fallback.jpg&amp;#39;&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h2 data-hextra-search-id="preview-images-that-make-themselves"&gt;Preview images that make themselves&lt;span class="hx:absolute hx:-mt-20" id="preview-images-that-make-themselves"&gt;&lt;/span&gt;
&lt;a href="#preview-images-that-make-themselves" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;When someone shares a link on LinkedIn or WhatsApp, the card image is what catches the eye. I did not want to open Canva for every new article, so Hugo generates that image itself.&lt;/p&gt;
&lt;p&gt;While building the site, it draws one image per page, in both languages, with the article title, the series name when there is one, my photo and my name. I publish an article and the image comes with it. If I change my photo on Sessionize, every image picks up the new one on the next deploy.&lt;/p&gt;
&lt;p&gt;This is the image the blog generated for the last article in the AI-Friendly Architecture series:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://luizschons.com/images/posts/hugo-sessionize-cron-blog-setup/preview-en.webp" alt="Preview image generated automatically for the article Agent Observability with OpenTelemetry" loading="lazy" /&gt;&lt;/p&gt;
&lt;p&gt;No external service, no headless browser: just Hugo&amp;rsquo;s own image filters applied on top of a white background. The heart of the &lt;code&gt;og-image.html&lt;/code&gt; partial is this:&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-go-html-template" data-lang="go-html-template"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$filters&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;slice&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;images&lt;/span&gt;&lt;span class="na"&gt;.Text&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$kicker&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dict&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;font&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$medium&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;size&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;24&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;color&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;#64748b&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;x&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;80&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;y&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;62&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;-}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;range&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$i&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$l&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$lines&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;-}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$filters&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$filters&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;append&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;images&lt;/span&gt;&lt;span class="na"&gt;.Text&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$l&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dict&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;font&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$bold&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;size&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$size&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;color&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;#111827&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;x&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;78&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;y&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;110&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mul&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$i&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$lineHeight&lt;/span&gt;&lt;span class="o"&gt;))))&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;-}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;-}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;with&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;resources&lt;/span&gt;&lt;span class="na"&gt;.Get&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;images/profile.jpg&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;-}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$avatar&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="na"&gt;.Fill&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;96x96 Center q90&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;images&lt;/span&gt;&lt;span class="na"&gt;.Filter&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;images&lt;/span&gt;&lt;span class="na"&gt;.Mask&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resources&lt;/span&gt;&lt;span class="na"&gt;.Get&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;og/avatar-mask.png&amp;#34;&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;-}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$filters&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$filters&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;append&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;images&lt;/span&gt;&lt;span class="na"&gt;.Overlay&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$avatar&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;80&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;502&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;-}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;-}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$img&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;resources&lt;/span&gt;&lt;span class="na"&gt;.Get&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;og/base.png&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;images&lt;/span&gt;&lt;span class="na"&gt;.Filter&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$filters&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;-}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;$img&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;resources&lt;/span&gt;&lt;span class="na"&gt;.Copy&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;printf&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;og/%s-%s.png&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$page&lt;/span&gt;&lt;span class="na"&gt;.Language.Lang&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;md5&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;$title&lt;/span&gt;&lt;span class="o"&gt;)))&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;-}}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The title is broken into lines beforehand (&lt;code&gt;$lines&lt;/code&gt;), with the font size picked by its length. After that, the meta tags just point at the image:&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-go-html-template" data-lang="go-html-template"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;with&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;partialCached&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;og-image.html&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="na"&gt;.&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="na"&gt;.RelPermalink&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;meta&lt;/span&gt; &lt;span class="na"&gt;property&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;og:image&amp;#34;&lt;/span&gt; &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;&lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="na"&gt;.Permalink&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;meta&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;twitter:card&amp;#34;&lt;/span&gt; &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;summary_large_image&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;}}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h2 data-hextra-search-id="topics-keep-reading-and-comments"&gt;Topics, &amp;ldquo;Keep reading&amp;rdquo; and comments&lt;span class="hx:absolute hx:-mt-20" id="topics-keep-reading-and-comments"&gt;&lt;/span&gt;
&lt;a href="#topics-keep-reading-and-comments" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Each article has a few topics in its front matter, like &lt;code&gt;tags: ['PHP', 'Performance']&lt;/code&gt;, named in the file&amp;rsquo;s language. Hugo builds a page per topic on its own (&lt;a href="https://luizschons.com/tags/php/" target="_blank" rel="noopener"&gt;PHP&lt;/a&gt;, for example), and the topics show up as filters at the top of the &lt;a href="https://luizschons.com/posts/" target="_blank" rel="noopener"&gt;article list&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;At the end of each article, the &amp;ldquo;Keep reading&amp;rdquo; block suggests up to three similar articles. Hugo picks them itself with &lt;code&gt;.Related&lt;/code&gt;, which scores what the articles have in common:&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-toml" data-lang="toml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;related&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;includeNewer&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;threshold&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="nx"&gt;related&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;indices&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;tags&amp;#39;&lt;/span&gt; &lt;span class="c"&gt;# shared topics weigh the most&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;weight&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="nx"&gt;related&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;indices&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;series&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;weight&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="nx"&gt;related&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;indices&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;date&amp;#39;&lt;/span&gt; &lt;span class="c"&gt;# tiebreaker: articles from around the same time&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;weight&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-go-html-template" data-lang="go-html-template"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;with&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;first&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;3&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;site&lt;/span&gt;&lt;span class="na"&gt;.RegularPages.Related&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="na"&gt;.&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;complement&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;slice&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="na"&gt;.&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;range&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="na"&gt;.&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;&lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="na"&gt;.RelPermalink&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="na"&gt;.Title&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;{{-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;}}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Comments use &lt;a href="https://giscus.app" target="_blank" rel="noopener"&gt;giscus&lt;/a&gt;, which stores each conversation as a Discussion in the blog&amp;rsquo;s repository. No database, no ads, and all you need to comment is a GitHub account. The part I like the most: the English and Portuguese versions of an article share the same conversation, because the conversation is keyed by the &lt;code&gt;translationKey&lt;/code&gt;, not by the URL:&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-html" data-lang="html"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;https://giscus.app/client.js&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="na"&gt;data-repo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;sschonss/meu-blog&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="na"&gt;data-mapping&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;specific&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="na"&gt;data-term&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;posts/{{ .Params.translationKey }}&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="na"&gt;data-lang&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;{{ if eq site.Language.Lang &amp;#34;&lt;/span&gt;&lt;span class="na"&gt;pt-br&lt;/span&gt;&lt;span class="err"&gt;&amp;#34;&lt;/span&gt; &lt;span class="err"&gt;}}&lt;/span&gt;&lt;span class="na"&gt;pt&lt;/span&gt;&lt;span class="err"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;else&lt;/span&gt; &lt;span class="err"&gt;}}&lt;/span&gt;&lt;span class="na"&gt;en&lt;/span&gt;&lt;span class="err"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;end&lt;/span&gt; &lt;span class="err"&gt;}}&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="na"&gt;data-loading&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;lazy&amp;#34;&lt;/span&gt; &lt;span class="na"&gt;async&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h2 data-hextra-search-id="the-blog-updates-itself-every-day"&gt;The blog updates itself every day&lt;span class="hx:absolute hx:-mt-20" id="the-blog-updates-itself-every-day"&gt;&lt;/span&gt;
&lt;a href="#the-blog-updates-itself-every-day" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;The site is static and hosted on GitHub Pages. A GitHub Actions workflow builds and publishes it, and it runs in three situations: when I push, every morning, and when I click &amp;ldquo;Run workflow&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;On every run it fetches the data from Sessionize, generates the icon and the preview images, builds the site with Hugo and publishes it. The daily run is what keeps talks and photo up to date, even in weeks when I write nothing. It also publishes scheduled articles: if I leave an article ready with a future date, Hugo ignores it until that day comes, and that morning&amp;rsquo;s run puts it live.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://luizschons.com/images/posts/hugo-sessionize-cron-blog-setup/architecture-en.svg" alt="Blog architecture: GitHub Actions combines the repository and Sessionize, publishes to GitHub Pages, and the browser fetches Sessionize again" loading="lazy" /&gt;&lt;/p&gt;
&lt;p&gt;The whole workflow fits on one screen. The &lt;code&gt;cron&lt;/code&gt; runs at 10:17 UTC (07:17 in Brasília), and every step that depends on Sessionize has an &lt;code&gt;|| echo&lt;/code&gt; so it never takes the deploy down:&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-yaml" data-lang="yaml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;push&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;branches&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="l"&gt;main]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;workflow_dispatch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;schedule&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;- &lt;span class="nt"&gt;cron&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;17 10 * * *&amp;#39;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;contents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;read&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;pages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;write&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;id-token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;write&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;jobs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;runs-on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;ubuntu-latest&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;environment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;github-pages&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;steps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;- &lt;span class="nt"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;actions/checkout@v4&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;submodules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;recursive &lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c"&gt;# the Hextra theme is a submodule&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;- &lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;Refresh Sessionize data&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;python3 scripts/sync_sessionize.py || echo &amp;#34;using committed data&amp;#34;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;- &lt;span class="nt"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;actions/setup-python@v5&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;python-version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;3.12&amp;#39;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;- &lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;Build favicons and backup photo&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="sd"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="sd"&gt; pip install --quiet pillow
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="sd"&gt; python3 scripts/build_favicons.py || echo &amp;#34;using committed icons&amp;#34;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;- &lt;span class="nt"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;peaceiris/actions-hugo@v3&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;hugo-version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;latest&amp;#39;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;extended&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;- &lt;span class="nt"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;hugo --minify&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;- &lt;span class="nt"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;actions/upload-pages-artifact@v3&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;./public&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;- &lt;span class="nt"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l"&gt;actions/deploy-pages@v4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Notice &lt;code&gt;contents: read&lt;/code&gt;: the workflow only reads the repository and never writes to it.&lt;/p&gt;
&lt;p&gt;A choice I am happy with: the workflow never commits to the repository. The Sessionize data is fetched at build time, so I could protect the &lt;code&gt;main&lt;/code&gt; branch so that only I can push changes. If Sessionize fails along the way, the build carries on with the last saved version.&lt;/p&gt;
&lt;p&gt;The protection is a ruleset on &lt;code&gt;main&lt;/code&gt; with three rules (restrict updates, restrict deletions and block force pushes) and a single bypass: the repository admin role, which only I have. Since GitHub Actions cannot be an exception in a personal repository&amp;rsquo;s ruleset, this setup only works because the workflow never needs to commit anything.&lt;/p&gt;
&lt;h2 data-hextra-search-id="measuring-without-cookies"&gt;Measuring without cookies&lt;span class="hx:absolute hx:-mt-20" id="measuring-without-cookies"&gt;&lt;/span&gt;
&lt;a href="#measuring-without-cookies" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Today I write in one place, in both languages, and everything else takes care of itself: talks, photo, preview images, topics and deploy. I track visits with &lt;a href="https://umami.is" target="_blank" rel="noopener"&gt;Umami&lt;/a&gt;, which does not use cookies and so needs no annoying consent banner.&lt;/p&gt;
&lt;p&gt;The script is only included in the production build and only counts the real domain, so running &lt;code&gt;hugo server&lt;/code&gt; locally does not skew the numbers:&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-go-html-template" data-lang="go-html-template"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;{{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;hugo&lt;/span&gt;&lt;span class="na"&gt;.IsProduction&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt; &lt;span class="na"&gt;defer&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;https://cloud.umami.is/script.js&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="na"&gt;data-website-id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;...&amp;#34;&lt;/span&gt; &lt;span class="na"&gt;data-domains&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;luizschons.com&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;{{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cp"&gt;}}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Besides visits, Umami gets click events: talks and events opened, language switches, moving between articles and outbound links. A single file listens to clicks on the whole page and recognizes the kind of link. The call to Umami is guarded, because it may not have loaded or may be blocked, and measuring must never break the page:&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-javascript" data-lang="javascript"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;track&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;umami&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;umami&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;track&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;click&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;closest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;a[href]&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hostname&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hostname&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;track&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;outbound&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;host&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hostname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;from&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pathname&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;});&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;That tells me, for example, how many people switch language from the notice and which talks get the most clicks.&lt;/p&gt;
&lt;h2 data-hextra-search-id="wrapping-up"&gt;Wrapping up&lt;span class="hx:absolute hx:-mt-20" id="wrapping-up"&gt;&lt;/span&gt;
&lt;a href="#wrapping-up" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;The code is open at &lt;a href="https://github.com/sschonss/meu-blog" target="_blank" rel="noopener"&gt;github.com/sschonss/meu-blog&lt;/a&gt;, with a README explaining each part. If you also write in more than one language and are tired of publishing everything twice, take a look, and reach out on &lt;a href="https://www.linkedin.com/in/luiz-schons/" target="_blank" rel="noopener"&gt;LinkedIn&lt;/a&gt; if you want to chat.&lt;/p&gt;</description></item><item><title>Ito under the hood: browser P2P multiplayer with no game server</title><link>https://luizschons.com/posts/how-ito-works/</link><pubDate>Tue, 03 Nov 2026 00:00:00 -0300</pubDate><guid>https://luizschons.com/posts/how-ito-works/</guid><description>
&lt;p&gt;&lt;a href="https://sschonss.github.io/ito/" target="_blank" rel="noopener"&gt;Ito&lt;/a&gt; is a cooperative card game where each person plays on their own phone. It&amp;rsquo;s a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps" target="_blank" rel="noopener"&gt;PWA&lt;/a&gt; (progressive web app): a website you can install and open as if it were an app.&lt;/p&gt;
&lt;p&gt;The site is just a handful of static files on &lt;a href="https://pages.github.com/" target="_blank" rel="noopener"&gt;GitHub Pages&lt;/a&gt;. There is no central server running the match. Even so, up to ten phones play together in real time, talking directly to each other.&lt;/p&gt;
&lt;p&gt;This article explains how that works, and the code is open in the &lt;a href="https://github.com/sschonss/ito" target="_blank" rel="noopener"&gt;Ito repository&lt;/a&gt;. It&amp;rsquo;s a companion to &lt;a href="https://luizschons.com/posts/personal-projects-as-a-lab/"&gt;Programming is still fun&lt;/a&gt;, where I explain why I build things out of curiosity and why, in the AI era, that became another way to learn.&lt;/p&gt;
&lt;p&gt;It isn&amp;rsquo;t a tutorial: it&amp;rsquo;s an explanation with diagrams, real output captured in a lab and simplified code snippets. You don&amp;rsquo;t need to know networking. Every acronym is explained the first time it shows up, and if one slips by, the &lt;a href="#glossary"&gt;quick glossary&lt;/a&gt; at the end sums them all up in one line each.&lt;/p&gt;
&lt;h3 data-hextra-search-id="the-game-in-five-moments"&gt;The game in five moments&lt;span class="hx:absolute hx:-mt-20" id="the-game-in-five-moments"&gt;&lt;/span&gt;
&lt;a href="#the-game-in-five-moments" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;So you don&amp;rsquo;t get lost among the terms, the article follows one game from start to finish. Each moment pulls in a piece of the tech:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;João creates the room.&lt;/strong&gt; His phone becomes the host, the room owner.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Maria types the code and joins.&lt;/strong&gt; The two phones have to find each other over the internet. This is the networking, connection and signaling part.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The cards are dealt.&lt;/strong&gt; Without anyone sending a single card.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Maria plays a card.&lt;/strong&gt; The move goes to the host, and the new game state comes back to everyone, signed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Someone&amp;rsquo;s connection drops.&lt;/strong&gt; The game has to keep going anyway.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 data-hextra-search-id="the-challenge-a-static-site-and-several-phones"&gt;The challenge: a static site and several phones&lt;span class="hx:absolute hx:-mt-20" id="the-challenge-a-static-site-and-several-phones"&gt;&lt;/span&gt;
&lt;a href="#the-challenge-a-static-site-and-several-phones" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;The traditional way to build a multiplayer game is to put a server in the middle. Each phone sends its move to the server, and the server relays it to the others. It&amp;rsquo;s like a group of friends who only talk through a mediator.&lt;/p&gt;
&lt;p&gt;GitHub Pages doesn&amp;rsquo;t run my code: it only serves files (HTML, CSS, JavaScript). So the question for the lab was: can the phones talk &lt;strong&gt;directly to each other&lt;/strong&gt;, with no mediator?&lt;/p&gt;
&lt;p&gt;They can, with &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API" target="_blank" rel="noopener"&gt;WebRTC&lt;/a&gt; (Web Real-Time Communication). It&amp;rsquo;s the technology browsers use for video calls, and it ships with every modern browser, with nothing to install.&lt;/p&gt;
&lt;p&gt;Besides audio and video, WebRTC has the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel" target="_blank" rel="noopener"&gt;&lt;strong&gt;data channel&lt;/strong&gt;&lt;/a&gt;. Think of it as a pipe between two browsers that carries any data: in Ito, the text of each move.&lt;/p&gt;
&lt;p&gt;This model is called &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/P2P" target="_blank" rel="noopener"&gt;&lt;strong&gt;P2P&lt;/strong&gt;&lt;/a&gt; (peer-to-peer). Each phone talks to the others without going through a central server, like friends talking at the same table instead of through a switchboard operator.&lt;/p&gt;
&lt;p&gt;The channel is also encrypted with &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/DTLS" target="_blank" rel="noopener"&gt;&lt;strong&gt;DTLS&lt;/strong&gt;&lt;/a&gt; (Datagram Transport Layer Security). It&amp;rsquo;s the version of &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/TLS" target="_blank" rel="noopener"&gt;TLS&lt;/a&gt;, the HTTPS padlock, made for this kind of connection. In practice, nobody along the way can read the moves.&lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s one catch: to open that channel, the two sides have to find each other first, and the internet doesn&amp;rsquo;t make that easy. The rest of the article is the story of that meeting, and then of what happens once it works.&lt;/p&gt;
&lt;p&gt;Here is the overall map (the full network design is documented in &lt;a href="https://github.com/sschonss/ito/blob/main/docs/p2p.md" target="_blank" rel="noopener"&gt;docs/p2p.md&lt;/a&gt;, in Portuguese):&lt;/p&gt;
&lt;p&gt;&lt;img src="https://luizschons.com/images/posts/how-ito-works/overview-en.svg" alt="Ito overview. The host and a guest use Nostr relays and MQTT brokers only to find each other, exchanging SDP and ICE candidates. Then they talk over a direct WebRTC channel encrypted with DTLS. On the side, STUN helps each phone discover its public address, and a Cloudflare TURN, with 24-hour credentials handed out by a Worker, relays the data when the direct path is blocked. GitHub Pages only serves the site files" loading="lazy" /&gt;&lt;/p&gt;
&lt;p&gt;Don&amp;rsquo;t worry if half the names in the drawing don&amp;rsquo;t make sense yet. Each one comes up in the next sections, with an example.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In short:&lt;/strong&gt; WebRTC lets two browsers talk directly and with encryption. The hard part is getting them to find each other.&lt;/p&gt;
&lt;h3 data-hextra-search-id="what-the-game-looks-like"&gt;What the game looks like&lt;span class="hx:absolute hx:-mt-20" id="what-the-game-looks-like"&gt;&lt;/span&gt;
&lt;a href="#what-the-game-looks-like" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;To get a feel for what is being synchronized, these are real screenshots of the live version of Ito, taken in a browser with a phone-sized screen (the game&amp;rsquo;s interface is in Portuguese only).&lt;/p&gt;
&lt;p&gt;On the left, the home screen, where you create a room. On the right, the room with two people: the room code at the top, the invite buttons and the list of who has joined, with the host marked.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://luizschons.com/images/posts/how-ito-works/ito-telas-inicio-sala.webp" alt="Two real screenshots of Ito on a phone, side by side, with the interface in Portuguese. On the left, the home screen, with the headline “Pense no número. Fale o tema.” (think of the number, say the theme) and the “Criar sala” (create room) card, with the number of rounds and the theme categories. On the right, the room as seen by the host: the code FVGZ-FYFH at the top, the Copy, QR code and Invite buttons, and the “Na sala” (in the room) list with João, marked as you and host, and Maria, both with a green connected dot. At the bottom, the “Começar partida” (start game) button" loading="lazy" /&gt;&lt;/p&gt;
&lt;p&gt;Those two people were two browser windows in the lab, each pretending to be a phone. Maria&amp;rsquo;s name showed up on the host&amp;rsquo;s list because the two browsers managed to open the direct channel. How that happens is the subject from here on.&lt;/p&gt;
&lt;h2 data-hextra-search-id="a-bit-of-networking-no-specialist-required"&gt;A bit of networking, no specialist required&lt;span class="hx:absolute hx:-mt-20" id="a-bit-of-networking-no-specialist-required"&gt;&lt;/span&gt;
&lt;a href="#a-bit-of-networking-no-specialist-required" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Before talking about WebRTC, it helps to understand why two phones can&amp;rsquo;t simply &amp;ldquo;call&amp;rdquo; each other. There are three ideas: IP address, private address and NAT.&lt;/p&gt;
&lt;h3 data-hextra-search-id="ip-address-the-delivery-address"&gt;IP address: the delivery address&lt;span class="hx:absolute hx:-mt-20" id="ip-address-the-delivery-address"&gt;&lt;/span&gt;
&lt;a href="#ip-address-the-delivery-address" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;Every connected device has an &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/IP_Address" target="_blank" rel="noopener"&gt;&lt;strong&gt;IP address&lt;/strong&gt;&lt;/a&gt;, a number that says where data packets should go, like the address on a letter. Something like &lt;code&gt;203.0.113.5&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;But there are two kinds:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Public address:&lt;/strong&gt; unique on the whole internet. Anyone in the world can send packets to it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Private address:&lt;/strong&gt; only valid inside a local network, like your home. Ranges such as &lt;code&gt;192.168.x.x&lt;/code&gt; and &lt;code&gt;10.x.x.x&lt;/code&gt; are reserved for this, and millions of homes use the same numbers at the same time. The &lt;code&gt;192.168.0.10&lt;/code&gt; in your home and the one next door are different devices.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Every address in this article is an &lt;strong&gt;example&lt;/strong&gt;, taken from ranges reserved for documentation. None belongs to a real device.&lt;/p&gt;
&lt;h3 data-hextra-search-id="nat-a-building-with-a-single-address"&gt;NAT: a building with a single address&lt;span class="hx:absolute hx:-mt-20" id="nat-a-building-with-a-single-address"&gt;&lt;/span&gt;
&lt;a href="#nat-a-building-with-a-single-address" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;If every home uses private addresses, how does data reach your phone? Through &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/NAT" target="_blank" rel="noopener"&gt;&lt;strong&gt;NAT&lt;/strong&gt;&lt;/a&gt; (Network Address Translation), which runs on the router.&lt;/p&gt;
&lt;p&gt;Think of an apartment building. The street only knows the building&amp;rsquo;s address (the public IP, &lt;code&gt;203.0.113.5&lt;/code&gt;). Inside, each apartment has a number (the private IP, &lt;code&gt;192.168.0.10&lt;/code&gt;, &lt;code&gt;192.168.0.11&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;The router is the doorman. When a resident sends a letter out, he notes &amp;ldquo;the reply to this letter goes to apartment 10&amp;rdquo; and swaps the sender for the building&amp;rsquo;s address. When the reply arrives, he checks the note and delivers it to the right apartment.&lt;/p&gt;
&lt;p&gt;In practice, the note uses a &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Port" target="_blank" rel="noopener"&gt;&lt;strong&gt;port&lt;/strong&gt;&lt;/a&gt;: an extra number that goes along with the address, as in &lt;code&gt;203.0.113.5:61000&lt;/code&gt;. Think of it as the apartment number written on the envelope.&lt;/p&gt;
&lt;p&gt;The detail that matters: the doorman only delivers what is a &lt;strong&gt;reply&lt;/strong&gt; to something a resident sent. A letter that arrives from outside without anyone asking for it has no note, so it gets dropped. That&amp;rsquo;s great for security and terrible for anyone who wants a direct connection.&lt;/p&gt;
&lt;h3 data-hextra-search-id="why-a-phone-on-4g-and-one-on-wi-fi-cant-find-each-other"&gt;Why a phone on 4G and one on Wi-Fi can&amp;rsquo;t find each other&lt;span class="hx:absolute hx:-mt-20" id="why-a-phone-on-4g-and-one-on-wi-fi-cant-find-each-other"&gt;&lt;/span&gt;
&lt;a href="#why-a-phone-on-4g-and-one-on-wi-fi-cant-find-each-other" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;Now put the pieces together, at the moment Maria tries to join João&amp;rsquo;s room. João&amp;rsquo;s phone is on home Wi-Fi, with the private address &lt;code&gt;192.168.0.10&lt;/code&gt;, behind the router. Maria&amp;rsquo;s phone is on 4G.&lt;/p&gt;
&lt;p&gt;Mobile carriers have so many customers that they run NAT at scale, called &lt;strong&gt;CGNAT&lt;/strong&gt; (Carrier-Grade NAT). The phone gets an internal address (something like &lt;code&gt;100.64.12.7&lt;/code&gt;) and shares one public address with thousands of other customers. It&amp;rsquo;s a huge building with a single doorman.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://luizschons.com/images/posts/how-ito-works/nat-en.svg" alt="NAT diagram. On the left, the home network: a phone at 192.168.0.10 and a laptop at 192.168.0.11 connected to a router that shows the address 203.0.113.5 to the outside. On the right, the mobile network: a phone on 4G at 100.64.12.7 behind the carrier’s CGNAT, which shows 198.51.100.20 to the outside. In the middle, the internet, which only sees the outside addresses. A dashed red arrow shows the 4G phone trying to come straight into the home router and being blocked, because it arrived from outside unasked. The addresses are examples" loading="lazy" /&gt;&lt;/p&gt;
&lt;p&gt;If Maria tries to send something to &lt;code&gt;192.168.0.10&lt;/code&gt;, it goes nowhere: that address only exists inside João&amp;rsquo;s home. If she tries the public address of his router, the router has no note and drops it. And the same goes the other way.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In short:&lt;/strong&gt; each doorman only lets replies in. If both phones wait for the other to knock first, nobody gets in. That&amp;rsquo;s the problem WebRTC has to solve.&lt;/p&gt;
&lt;h2 data-hextra-search-id="how-the-connection-crosses-the-network-ice-stun-and-turn"&gt;How the connection crosses the network: ICE, STUN and TURN&lt;span class="hx:absolute hx:-mt-20" id="how-the-connection-crosses-the-network-ice-stun-and-turn"&gt;&lt;/span&gt;
&lt;a href="#how-the-connection-crosses-the-network-ice-stun-and-turn" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;WebRTC breaks this deadlock with three tools. It helps to keep one sentence for each:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;ICE&lt;/strong&gt; runs the search: it gathers the possible addresses and tests which path works.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;STUN&lt;/strong&gt; tells each phone &amp;ldquo;this is how you look from outside&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;TURN&lt;/strong&gt; is plan B: a server that relays the data when no direct path opens.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;MDN has a good overview of the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Protocols" target="_blank" rel="noopener"&gt;WebRTC protocols&lt;/a&gt;, if you want to go further.&lt;/p&gt;
&lt;h3 data-hextra-search-id="ice-candidates-where-you-can-find-me"&gt;ICE candidates: &amp;ldquo;where you can find me&amp;rdquo;&lt;span class="hx:absolute hx:-mt-20" id="ice-candidates-where-you-can-find-me"&gt;&lt;/span&gt;
&lt;a href="#ice-candidates-where-you-can-find-me" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/ICE" target="_blank" rel="noopener"&gt;&lt;strong&gt;ICE&lt;/strong&gt;&lt;/a&gt; (Interactive Connectivity Establishment) is the process the browser uses to discover paths to the other side.&lt;/p&gt;
&lt;p&gt;Each address where a phone &lt;em&gt;might&lt;/em&gt; be reachable becomes an &lt;strong&gt;ICE candidate&lt;/strong&gt;. It&amp;rsquo;s a guess: &amp;ldquo;try to find me here&amp;rdquo;. There are three kinds:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;host:&lt;/strong&gt; the address on the local network itself (&lt;code&gt;192.168.0.10:50000&lt;/code&gt;). It only works if both are on the same network.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;srflx&lt;/strong&gt; (server reflexive): the public address the router uses for that phone (&lt;code&gt;203.0.113.5:61000&lt;/code&gt;). It&amp;rsquo;s discovered with the help of a STUN server.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;relay:&lt;/strong&gt; an address borrowed from a TURN server, which relays the data. It&amp;rsquo;s plan B.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Each side gathers its candidates and sends the list to the other (the signaling section shows how). Then ICE builds pairs, one of my candidates with one of theirs, and tests them all, like trying the keys on a key ring until one opens the door.&lt;/p&gt;
&lt;p&gt;The pair that works wins, preferably the most direct one. TURN comes last.&lt;/p&gt;
&lt;h3 data-hextra-search-id="stun-from-outside-how-do-you-see-me"&gt;STUN: &amp;ldquo;from outside, how do you see me?&amp;rdquo;&lt;span class="hx:absolute hx:-mt-20" id="stun-from-outside-how-do-you-see-me"&gt;&lt;/span&gt;
&lt;a href="#stun-from-outside-how-do-you-see-me" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;A phone doesn&amp;rsquo;t know its public address on its own: it only knows &lt;code&gt;192.168.0.10&lt;/code&gt;. The one who knows is the router, which swaps the sender along the way.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/STUN" target="_blank" rel="noopener"&gt;&lt;strong&gt;STUN&lt;/strong&gt;&lt;/a&gt; (Session Traversal Utilities for NAT) solves this with a single question. The phone sends a packet to a STUN server on the internet, and the server replies with the address the packet came from. It&amp;rsquo;s like calling a friend and asking &amp;ldquo;what number shows up on your screen?&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://luizschons.com/images/posts/how-ito-works/stun-en.svg" alt="STUN exchange in four steps. 1: the phone, at 192.168.0.10, asks “who am I?” from port 50000. 2: the router swaps the sender and the question reaches the STUN server from 203.0.113.5:61000; the router notes that port 61000 belongs to the phone. 3: the STUN server answers “I see you at 203.0.113.5:61000”. 4: the router forwards the answer to the phone. In the end, the phone has two ICE candidates: host 192.168.0.10:50000, which only works inside the home, and srflx 203.0.113.5:61000, found via STUN. Example addresses and ports" loading="lazy" /&gt;&lt;/p&gt;
&lt;p&gt;Notice the side effect: by asking the question, the phone also left a note with the doorman. That&amp;rsquo;s the basis of the direct path, which works like this:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;João and Maria trade their srflx candidates, that is, the public addresses STUN showed them.&lt;/li&gt;
&lt;li&gt;Both send packets to the other&amp;rsquo;s public address &lt;strong&gt;at the same time&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;To João&amp;rsquo;s router, the packet arriving from Maria looks like the reply to something João just sent, so it lets it through. The same happens on the other side.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This technique is informally called &lt;em&gt;hole punching&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;STUN is cheap: it answers one question and carries no game data. Ito uses the default STUN servers from Trystero (a library I&amp;rsquo;ll get to shortly): Google&amp;rsquo;s (&lt;code&gt;stun.l.google.com&lt;/code&gt; and variants) and Cloudflare&amp;rsquo;s (&lt;code&gt;stun.cloudflare.com&lt;/code&gt;).&lt;/p&gt;
&lt;h3 data-hextra-search-id="when-the-direct-path-fails-turn"&gt;When the direct path fails: TURN&lt;span class="hx:absolute hx:-mt-20" id="when-the-direct-path-fails-turn"&gt;&lt;/span&gt;
&lt;a href="#when-the-direct-path-fails-turn" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;Hole punching doesn&amp;rsquo;t always work. The most common cases:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Symmetric NAT:&lt;/strong&gt; some routers use a different port for each destination. The port STUN saw doesn&amp;rsquo;t work for talking to the other phone, so the srflx address is useless.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Corporate and university networks:&lt;/strong&gt; many block &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/UDP" target="_blank" rel="noopener"&gt;UDP&lt;/a&gt;, the kind of packet WebRTC prefers (fast, with no delivery confirmation, good for real time). They only let web traffic out, on ports 80 and 443.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Carrier CGNAT:&lt;/strong&gt; with thousands of customers behind the same address, the carrier&amp;rsquo;s NAT tends to be stricter, and the direct path between two phones on 4G may not open.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For these cases there is &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/TURN" target="_blank" rel="noopener"&gt;&lt;strong&gt;TURN&lt;/strong&gt;&lt;/a&gt; (Traversal Using Relays around NAT). Instead of trying to reach each other directly, both phones open a connection &lt;strong&gt;outward&lt;/strong&gt;, to a TURN server, which almost every network allows. TURN forwards the packets from one to the other.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s a mail carrier, not a reader. The channel stays DTLS-encrypted end to end, so TURN sees encrypted bytes, not the moves.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://luizschons.com/images/posts/how-ito-works/paths-en.svg" alt="Two paths side by side. On the left, the direct path: phone A, on home Wi-Fi, behind a NAT, and phone B, on 4G, behind a CGNAT, connected directly, because both knock on the door at the same time using the addresses found via STUN. On the right, through TURN: each phone connects outward to a Cloudflare TURN server, which relays between them. Below, the reasons the direct path fails, symmetric NAT, a corporate network blocking UDP and carrier CGNAT, and a reminder that, either way, DTLS holds end to end and TURN sees encrypted bytes, not the moves" loading="lazy" /&gt;&lt;/p&gt;
&lt;p&gt;Ito&amp;rsquo;s TURN is &lt;a href="https://developers.cloudflare.com/realtime/turn/" target="_blank" rel="noopener"&gt;Cloudflare Realtime TURN&lt;/a&gt;. A TURN server needs credentials, and I didn&amp;rsquo;t want to leave a password in the site&amp;rsquo;s code, where anyone can read it.&lt;/p&gt;
&lt;p&gt;The solution was a &lt;a href="https://workers.cloudflare.com/" target="_blank" rel="noopener"&gt;Cloudflare Worker&lt;/a&gt;, a small function that runs on Cloudflare with no server to maintain:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The app asks the Worker for temporary credentials, valid for 24 hours, and reuses them until about 5 minutes before they expire.&lt;/li&gt;
&lt;li&gt;The secret key lives only in the Worker, which only answers requests from the game&amp;rsquo;s origin and &lt;code&gt;localhost&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The details are in &lt;a href="https://github.com/sschonss/ito/blob/main/docs/turn.md" target="_blank" rel="noopener"&gt;docs/turn.md&lt;/a&gt; (in Portuguese).&lt;/p&gt;
&lt;p&gt;And if the Worker fails or takes more than about 3 seconds? The room opens anyway, with only STUN and the direct connection. TURN is a backup, not a requirement.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In short:&lt;/strong&gt; ICE tests paths, STUN finds each phone&amp;rsquo;s public address so the direct path can be tried, and TURN relays the encrypted data when the direct path doesn&amp;rsquo;t open.&lt;/p&gt;
&lt;h2 data-hextra-search-id="how-the-phones-find-each-other-signaling"&gt;How the phones find each other: signaling&lt;span class="hx:absolute hx:-mt-20" id="how-the-phones-find-each-other-signaling"&gt;&lt;/span&gt;
&lt;a href="#how-the-phones-find-each-other-signaling" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;By now, each phone knows &lt;strong&gt;where it can be found&lt;/strong&gt; (its ICE candidates). It still has to tell the other one.&lt;/p&gt;
&lt;p&gt;And there&amp;rsquo;s a chicken-and-egg problem. To talk directly, they need to trade this information. To trade information, they would already need to be talking.&lt;/p&gt;
&lt;p&gt;So that first exchange goes through a third party. It&amp;rsquo;s called &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Signaling_and_video_calling" target="_blank" rel="noopener"&gt;&lt;strong&gt;signaling&lt;/strong&gt;&lt;/a&gt;: like two friends texting to agree on a meeting spot before they see each other. WebRTC deliberately doesn&amp;rsquo;t define how it happens. Each application picks its own channel.&lt;/p&gt;
&lt;h3 data-hextra-search-id="what-needs-to-be-exchanged"&gt;What needs to be exchanged&lt;span class="hx:absolute hx:-mt-20" id="what-needs-to-be-exchanged"&gt;&lt;/span&gt;
&lt;a href="#what-needs-to-be-exchanged" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;There are two kinds of notes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;SDP offer and answer&lt;/strong&gt;, the &amp;ldquo;what I can do&amp;rdquo;. &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/SDP" target="_blank" rel="noopener"&gt;SDP&lt;/a&gt; (Session Description Protocol) is a spec sheet: &amp;ldquo;I want to open a data channel, these are my security parameters&amp;rdquo;. One side sends the &lt;strong&gt;offer&lt;/strong&gt;, the other sends back the &lt;strong&gt;answer&lt;/strong&gt;, and that&amp;rsquo;s how both agree on the shape of the conversation.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ICE candidates&lt;/strong&gt;, the &amp;ldquo;where you can find me&amp;rdquo;: the list of addresses from the previous section.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 data-hextra-search-id="the-bulletin-board"&gt;The bulletin board&lt;span class="hx:absolute hx:-mt-20" id="the-bulletin-board"&gt;&lt;/span&gt;
&lt;a href="#the-bulletin-board" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;The best image I found is a &lt;strong&gt;cork bulletin board&lt;/strong&gt; in a busy hallway. Anyone can pin a note and anyone can read it. Ito uses the board like this:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;The room code is the board&amp;rsquo;s name.&lt;/strong&gt; Whoever knows the code (&lt;code&gt;FVGZ-FYFH&lt;/code&gt;, for example) knows which board to look at.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Each phone pins an &amp;ldquo;I&amp;rsquo;m here&amp;rdquo;&lt;/strong&gt; on the board, with a random identifier.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Each one also has a personal mailbox&lt;/strong&gt;, another name derived from the board plus their own identifier. Whoever sees someone&amp;rsquo;s &amp;ldquo;I&amp;rsquo;m here&amp;rdquo; leaves the &lt;strong&gt;offer&lt;/strong&gt; in that person&amp;rsquo;s mailbox. The person answers in the offerer&amp;rsquo;s mailbox, and the ICE candidates follow the same route.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The notes are encrypted.&lt;/strong&gt; The key comes from the room code, so anyone walking past the board without the code sees only meaningless letters and numbers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The board never carries the game.&lt;/strong&gt; As soon as the direct channel opens, nobody looks at it again. No move, card or chat message goes through it.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;A detail about the board&amp;rsquo;s name: in practice, it&amp;rsquo;s a &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Hash_function" target="_blank" rel="noopener"&gt;hash&lt;/a&gt; of the room code. A hash is a &amp;ldquo;fingerprint&amp;rdquo; of a text: the same text always gives the same result, and any change gives a very different one.&lt;/p&gt;
&lt;p&gt;The input text is &lt;code&gt;Trystero@&lt;/code&gt; + the app name + &lt;code&gt;@&lt;/code&gt; + the room code. In one of the lab rooms, with the code &lt;code&gt;NUFW-FYFH&lt;/code&gt;, the board&amp;rsquo;s name was &lt;code&gt;3x5w6s4e1l5n636x5s235r2n5539gk1k6643c&lt;/code&gt;. You can check it: it&amp;rsquo;s exactly the SHA-1 (a hash algorithm) of that text.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://luizschons.com/images/posts/how-ito-works/signal-en.svg" alt="Signaling sequence diagram with three columns: host, board (Nostr relays and MQTT brokers) and guest. 1 and 2: each pins “I’m here” on the room’s board. 3: the board shows the host the guest’s note. 4 and 5: the host leaves the encrypted SDP offer in the guest’s mailbox, and the board delivers it. 6 and 7: the guest leaves the encrypted SDP answer in the host’s mailbox, and the board delivers it. 8: encrypted ICE candidates both ways. A green band says the board steps aside and never carries a move. 9: ICE tests the address pairs and the WebRTC channel opens, with DTLS. 10: the game goes direct, with act, state, ack and tick" loading="lazy" /&gt;&lt;/p&gt;
&lt;p&gt;The names at the end of the drawing (&lt;code&gt;act&lt;/code&gt;, &lt;code&gt;state&lt;/code&gt;, &lt;code&gt;ack&lt;/code&gt; and &lt;code&gt;tick&lt;/code&gt;) are the game&amp;rsquo;s message types. They get a proper explanation in the section about the host.&lt;/p&gt;
&lt;p&gt;A detail that often gets oversimplified: it isn&amp;rsquo;t always the host who sends the offer. It&amp;rsquo;s whoever sees the other&amp;rsquo;s &amp;ldquo;I&amp;rsquo;m here&amp;rdquo;. If both send at the same time, a tie-break rule in the library picks one. In the lab test, the host was already on the board, saw the guest arrive and sent the offer.&lt;/p&gt;
&lt;h3 data-hextra-search-id="who-plays-the-board"&gt;Who plays the board&lt;span class="hx:absolute hx:-mt-20" id="who-plays-the-board"&gt;&lt;/span&gt;
&lt;a href="#who-plays-the-board" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;Ito uses the &lt;a href="https://github.com/dmotz/trystero" target="_blank" rel="noopener"&gt;Trystero&lt;/a&gt; library, which does this signaling over public networks that already exist. It uses two of them at the same time:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://nostr.com/" target="_blank" rel="noopener"&gt;Nostr&lt;/a&gt;:&lt;/strong&gt; an open protocol for decentralized social networks. Messages travel through &lt;strong&gt;relays&lt;/strong&gt;, public servers that store and pass on notes to whoever asks.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://mqtt.org/" target="_blank" rel="noopener"&gt;MQTT&lt;/a&gt;:&lt;/strong&gt; a lightweight messaging protocol used in IoT (the internet of things: sensors, smart bulbs). In it, &lt;strong&gt;brokers&lt;/strong&gt;, also public servers, deliver each message to whoever subscribes to a topic.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For Ito, both are boards: public places where you can pin and read notes by name. The room code is the room name on both networks and also the password for the negotiation.&lt;/p&gt;
&lt;p&gt;In the snippet below, simplified from &lt;a href="https://github.com/sschonss/ito/blob/main/js/net.js" target="_blank" rel="noopener"&gt;js/net.js&lt;/a&gt;, notice that the room code (&lt;code&gt;code&lt;/code&gt;) shows up twice: once as the password and once as the room name.&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-javascript" data-lang="javascript"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;// for each network (Nostr and MQTT)
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kr"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;room&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;lib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;joinRoom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;appId&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;APP_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;turnConfig&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="c1"&gt;// the room code is also the password
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="c1"&gt;// and the room name
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3 data-hextra-search-id="what-a-real-note-looks-like"&gt;What a real note looks like&lt;span class="hx:absolute hx:-mt-20" id="what-a-real-note-looks-like"&gt;&lt;/span&gt;
&lt;a href="#what-a-real-note-looks-like" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;In the lab, the test recorded the messages the browsers sent to a Nostr relay. This is the host&amp;rsquo;s &amp;ldquo;I&amp;rsquo;m here&amp;rdquo;, shortened. Look at two fields: the &lt;code&gt;x&lt;/code&gt; tag, which is the board&amp;rsquo;s name, and &lt;code&gt;content&lt;/code&gt;, which carries only the random identifier (&lt;code&gt;kind&lt;/code&gt; is the Nostr event type).&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-json" data-lang="json"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;EVENT&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;kind&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;22750&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;tags&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;x&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;3x5w6s4e1l5n636x5s235r2n5539gk1k6643c&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;content&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;{\&amp;#34;peerId\&amp;#34;:\&amp;#34;Hz5mLideyfm3wcxbVDYG\&amp;#34;}&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;pubkey&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;6b4303fa…&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;&amp;#34;sig&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;…&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And this is the offer it left in the guest&amp;rsquo;s mailbox. Notice two differences:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;x&lt;/code&gt; tag is now a different name: the guest&amp;rsquo;s personal mailbox.&lt;/li&gt;
&lt;li&gt;The SDP is encrypted with AES-GCM, a common encryption algorithm. Before the &lt;code&gt;$&lt;/code&gt; comes the initialization vector, a random number that makes the same text come out different each time it&amp;rsquo;s encrypted. After it comes the ciphertext in &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Base64" target="_blank" rel="noopener"&gt;base64&lt;/a&gt;, a way of writing bytes using only letters and numbers.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;content&lt;/code&gt; travels as a string in the message; here it&amp;rsquo;s formatted to fit:&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-json" data-lang="json"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;EVENT&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;kind&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;22620&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;tags&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;x&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;s1d44364b6k42334vx6y4z2s341065511h505p&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;content&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;peerId&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Hz5mLideyfm3wcxbVDYG&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;offerId&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;PjBc6cjOrcF7&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;offer&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;162,62,20,126,…$HWJjPQeza48JSSPl8zwr…&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Whoever has the room code decrypts it and finds a regular SDP. Below is an excerpt of the SDP the host&amp;rsquo;s browser generated in the same test, read straight from the browser API, with identifiers masked. You don&amp;rsquo;t need to read all of it: the lines that matter are the first one, the &lt;code&gt;candidate&lt;/code&gt; one and the &lt;code&gt;fingerprint&lt;/code&gt; one.&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;m=application 12988 UDP/DTLS/SCTP webrtc-datachannel
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;a=candidate:2032783209 1 udp 8191 104.30.x.x 12988 typ relay …
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;a=ice-ufrag:(masked)
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;a=fingerprint:sha-256 B9:8F:11:F5:…:54:62:E1
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;a=setup:actpass
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;a=sctp-port:5000&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Reading those three lines:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;m=application ... webrtc-datachannel&lt;/code&gt; says &amp;ldquo;I want a data channel, not audio or video&amp;rdquo;. The &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/SCTP" target="_blank" rel="noopener"&gt;SCTP&lt;/a&gt; in it is the protocol the data channel uses underneath.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;a=candidate&lt;/code&gt; is an ICE candidate of type &lt;code&gt;relay&lt;/code&gt;, that is, an address borrowed from TURN.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;fingerprint&lt;/code&gt; is the fingerprint of the DTLS &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Digital_certificate" target="_blank" rel="noopener"&gt;certificate&lt;/a&gt;. The other side uses it to make sure it&amp;rsquo;s encrypting with whoever it negotiated with, and not with someone in the middle.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 data-hextra-search-id="two-networks-at-once"&gt;Two networks at once&lt;span class="hx:absolute hx:-mt-20" id="two-networks-at-once"&gt;&lt;/span&gt;
&lt;a href="#two-networks-at-once" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;Using two boards has an interesting side effect: the same person can arrive twice, once through each network. Maria may show up through Nostr and, a moment later, again through MQTT.&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s why messages are &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Idempotent" target="_blank" rel="noopener"&gt;&lt;strong&gt;idempotent&lt;/strong&gt;&lt;/a&gt;: receiving the same message twice is the same as receiving it once. In practice:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The state has a version, so a repeated copy changes nothing.&lt;/li&gt;
&lt;li&gt;Reactions have an &lt;code&gt;id&lt;/code&gt;, so they don&amp;rsquo;t count twice.&lt;/li&gt;
&lt;li&gt;Someone only counts as disconnected when they drop from &lt;strong&gt;both networks&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The redundancy showed up in the lab itself: on the test network, no public MQTT broker accepted a connection, and the room opened anyway, through Nostr alone.&lt;/p&gt;
&lt;h3 data-hextra-search-id="which-boards-and-what-the-screen-shows-while-searching"&gt;Which boards, and what the screen shows while searching&lt;span class="hx:absolute hx:-mt-20" id="which-boards-and-what-the-screen-shows-while-searching"&gt;&lt;/span&gt;
&lt;a href="#which-boards-and-what-the-screen-shows-while-searching" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;Out of the box, Trystero uses a default list of boards, and some relays on that list had already gone offline or started requiring a login to accept notes.&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s why Ito ships its own list: &lt;strong&gt;8 Nostr relays&lt;/strong&gt;, picked because they accept anonymous writes (no account, no authentication), and &lt;strong&gt;4 MQTT brokers&lt;/strong&gt;. The list lives in the &lt;code&gt;RELAYS&lt;/code&gt; constant, in &lt;a href="https://github.com/sschonss/ito/blob/main/js/core.js" target="_blank" rel="noopener"&gt;js/core.js&lt;/a&gt;, and is handed to Trystero in full, replacing the default list.&lt;/p&gt;
&lt;p&gt;The 8 relays answer on &lt;strong&gt;port 443&lt;/strong&gt;, the HTTPS one, the same as any website. That matters because many mobile and corporate networks only let web traffic out and cut every other port.&lt;/p&gt;
&lt;p&gt;Three of the four MQTT brokers use ports outside the web standard (8081, 8084 and 8884). On a network like that, the Nostr relays carry the signaling, just like in the lab described above.&lt;/p&gt;
&lt;p&gt;Finding the room can also take a while. If nobody shows up within 15 seconds, the app joins the board again on its own, up to 3 times, and shows which attempt it&amp;rsquo;s on (&amp;ldquo;Tentativa 2 de 4&amp;rdquo;, attempt 2 of 4, counting the first join).&lt;/p&gt;
&lt;p&gt;Meanwhile, Maria&amp;rsquo;s screen tells four situations apart, because each one calls for a different response (the game&amp;rsquo;s interface is in Portuguese; the meaning is what matters here):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;No internet:&lt;/strong&gt; the connection library didn&amp;rsquo;t even load. The problem is the phone&amp;rsquo;s own network.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Searching for the room:&lt;/strong&gt; the phone is on the boards, waiting for someone from the room to appear.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Almost there:&lt;/strong&gt; there&amp;rsquo;s already a channel to someone in the room, but the host&amp;rsquo;s signed state hasn&amp;rsquo;t arrived yet. If it never arrives, the screen says exactly that (&amp;ldquo;the host&amp;rsquo;s state didn&amp;rsquo;t arrive&amp;rdquo;) instead of pretending the room doesn&amp;rsquo;t exist.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Room not found:&lt;/strong&gt; the attempts ran out and nobody appeared. The screen suggests checking that whoever created the room has Ito open, and a &amp;ldquo;try again&amp;rdquo; button restarts the search.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To see the code: the 15 seconds and the limit of 3 extra attempts are the &lt;code&gt;CONNECT_TIMEOUT&lt;/code&gt; and &lt;code&gt;SEEK_TRIES&lt;/code&gt; constants, in &lt;a href="https://github.com/sschonss/ito/blob/main/js/core.js" target="_blank" rel="noopener"&gt;js/core.js&lt;/a&gt;, and joining the board again happens in the &lt;code&gt;armSeek&lt;/code&gt; function, in &lt;a href="https://github.com/sschonss/ito/blob/main/js/net.js" target="_blank" rel="noopener"&gt;js/net.js&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In short:&lt;/strong&gt; before the direct channel exists, the phones trade the spec sheet (SDP) and the addresses (ICE candidates) as encrypted notes on public boards, Nostr and MQTT. Once the channel opens, the board steps aside.&lt;/p&gt;
&lt;h2 data-hextra-search-id="what-the-lab-showed-the-connection-went-through-turn"&gt;What the lab showed: the connection went through TURN&lt;span class="hx:absolute hx:-mt-20" id="what-the-lab-showed-the-connection-went-through-turn"&gt;&lt;/span&gt;
&lt;a href="#what-the-lab-showed-the-connection-went-through-turn" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;The test opened the live Ito in two browser windows on the same lab machine, one as host and one as guest. Then it read &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/getStats" target="_blank" rel="noopener"&gt;&lt;code&gt;getStats()&lt;/code&gt;&lt;/a&gt;, the WebRTC function that reports which candidate pair was chosen.&lt;/p&gt;
&lt;p&gt;The summary is below, with addresses masked. The lines that matter are the first one, which shows the chosen pair (relay to relay), and the third one, which shows how TURN was reached.&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;selected pair: relay (local) &amp;lt;-&amp;gt; relay (remote), udp, rtt ~0.02 s
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;local candidate: relay 104.30.x.x
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; via turns:turn.cloudflare.com:443 (relayProtocol: tls)
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;transport: dtlsState connected, DTLS 1.3
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; cipher TLS_AES_128_GCM_SHA256&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;rtt&lt;/code&gt; (&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Round_Trip_Time" target="_blank" rel="noopener"&gt;round-trip time&lt;/a&gt;) is how long a packet takes to go and come back: about 20 milliseconds. The last line is the name of the cipher DTLS used.&lt;/p&gt;
&lt;p&gt;The lab network blocked outgoing UDP, like many corporate networks. ICE found no direct path, and the connection went out through Cloudflare&amp;rsquo;s TURN &lt;strong&gt;over TLS on port 443&lt;/strong&gt;, the same port as a regular HTTPS site.&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s exactly the scenario from the previous section: TURN kept the game going, and DTLS still protected everything inside the tunnel.&lt;/p&gt;
&lt;p&gt;The test couldn&amp;rsquo;t show the direct path. Even in a second run, with both windows on the same machine, the browser didn&amp;rsquo;t produce local UDP candidates on that network, so the only possible pair was relay to relay. On a regular home Wi-Fi network, the expected outcome is ICE picking a &lt;code&gt;host&lt;/code&gt; or &lt;code&gt;srflx&lt;/code&gt; pair, with no TURN, but the lab didn&amp;rsquo;t record that.&lt;/p&gt;
&lt;h2 data-hextra-search-id="the-card-trick-nobody-sends-the-cards"&gt;The card trick: nobody sends the cards&lt;span class="hx:absolute hx:-mt-20" id="the-card-trick-nobody-sends-the-cards"&gt;&lt;/span&gt;
&lt;a href="#the-card-trick-nobody-sends-the-cards" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;This is my favorite part. In an online card game, the intuition is that someone deals and sends each player their card. In Ito, &lt;strong&gt;the cards never travel&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;When the round starts, each phone computes the deck on its own, and they all reach the same result. The secret is a &lt;strong&gt;seeded pseudorandom generator&lt;/strong&gt;: an algorithm that produces numbers that look random but are always the same for the same seed (the starting text).&lt;/p&gt;
&lt;p&gt;Like a recipe: same ingredients, same cake in any kitchen.&lt;/p&gt;
&lt;p&gt;Ito&amp;rsquo;s recipe has three steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The seed is the text &lt;code&gt;room code|game number|round number&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A hash called xmur3 turns that text into a number, and the mulberry32 generator produces the &amp;ldquo;random&amp;rdquo; sequence from it.&lt;/li&gt;
&lt;li&gt;The &lt;a href="https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle" target="_blank" rel="noopener"&gt;Fisher-Yates&lt;/a&gt; shuffle uses that sequence to shuffle the cards from 1 to 100.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;In the snippet below, simplified from &lt;a href="https://github.com/sschonss/ito/blob/main/js/core.js" target="_blank" rel="noopener"&gt;js/core.js&lt;/a&gt;, notice that the only input is the seed text: nothing comes from the network.&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-javascript" data-lang="javascript"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;// same input text, same deck on every phone
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kr"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rng&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;seed&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;mulberry32&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;xmur3&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;seed&lt;/span&gt;&lt;span class="p"&gt;)());&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kr"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;deckFor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;game&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;round&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;shuffle&lt;/span&gt;&lt;span class="p"&gt;([...&lt;/span&gt;&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)].&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;rng&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sb"&gt;|&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;game&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sb"&gt;|&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;round&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;img src="https://luizschons.com/images/posts/how-ito-works/deck-en.svg" alt="The cards don’t travel. The seed text, room code, game and round, goes through the xmur3 hash, the mulberry32 generator and the Fisher-Yates shuffle, and every phone ends up with the same deck from 1 to 100. Only decisions cross the network: playing a card, the order, votes and clues" loading="lazy" /&gt;&lt;/p&gt;
&lt;p&gt;Only &lt;strong&gt;decisions&lt;/strong&gt; cross the network: &amp;ldquo;I played my card&amp;rdquo;, &amp;ldquo;I arranged the order like this&amp;rdquo;, votes and clues. Small messages, and no cards flying around.&lt;/p&gt;
&lt;p&gt;The room code also carries the settings. It&amp;rsquo;s 8 letters without I and O (so they aren&amp;rsquo;t confused with 1 and 0):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The first 4 are the random part of the room.&lt;/li&gt;
&lt;li&gt;The last 4 store, in base 24, the number of rounds and the chosen theme categories.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Whoever types the code already knows how the game was set up.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In short:&lt;/strong&gt; with the same seed, every phone computes the same deck. Only the players&amp;rsquo; decisions cross the network.&lt;/p&gt;
&lt;h2 data-hextra-search-id="who-runs-the-game-the-host"&gt;Who runs the game: the host&lt;span class="hx:absolute hx:-mt-20" id="who-runs-the-game-the-host"&gt;&lt;/span&gt;
&lt;a href="#who-runs-the-game-the-host" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;With several phones, who decides what&amp;rsquo;s true? In Ito the rule is simple: &lt;strong&gt;whoever creates the room is the host, and the host is the single source of truth&lt;/strong&gt;. The others are the guests.&lt;/p&gt;
&lt;p&gt;The inspiration came from the host model I knew from online FIFA and EA FC matches, where one side hosts the game and the other connects to it. In Ito, the host is João&amp;rsquo;s phone.&lt;/p&gt;
&lt;p&gt;Only the host changes the game state. The &lt;strong&gt;state&lt;/strong&gt; is a full snapshot of the game at that moment: who is in the room, the theme, who has played a card, the order on the table.&lt;/p&gt;
&lt;p&gt;The phones talk using a few message types. The names are short because they show up in the code:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;act&lt;/code&gt;&lt;/strong&gt; (action): a guest&amp;rsquo;s request, like &amp;ldquo;I played my card&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;state&lt;/code&gt;&lt;/strong&gt;: the full state, sent by the host on every change.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;ack&lt;/code&gt;&lt;/strong&gt; (acknowledge): the guest says &amp;ldquo;I got version 8&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;tick&lt;/code&gt;&lt;/strong&gt; (as in a clock&amp;rsquo;s tick): a pulse the host sends every 2 seconds, with the version and a hash of the state.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;pull&lt;/code&gt;&lt;/strong&gt;: the guest asks &amp;ldquo;send me the state again&amp;rdquo;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Each change bumps the state version (&lt;code&gt;ver&lt;/code&gt;), a counter that only goes up, and the host sends the full state. A guest only accepts a state newer than the one it has.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;tick&lt;/code&gt; works like a referee who, every so often, checks the scoreboard with everyone. It carries the version and the hash of the state: if any detail differs, the hash changes. Anyone out of sync asks for the state again.&lt;/p&gt;
&lt;p&gt;The snippet below is what a guest does on every &lt;code&gt;tick&lt;/code&gt;. Look at the condition: if the version or the hash doesn&amp;rsquo;t match what it has, it sends a &lt;code&gt;pull&lt;/code&gt;.&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-javascript" data-lang="javascript"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;// on a guest, on every tick from the host
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ver&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;my&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ver&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;h&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;stateHash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;my&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;guestSend&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;pull&amp;#39;&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt; &lt;span class="c1"&gt;// &amp;#34;send me the state again&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The snippet is a simplified version of the &lt;code&gt;dispatch&lt;/code&gt; function, in &lt;a href="https://github.com/sschonss/ito/blob/main/js/net.js" target="_blank" rel="noopener"&gt;js/net.js&lt;/a&gt;, and the &lt;code&gt;tick&lt;/code&gt; comes from the &lt;code&gt;syncTick&lt;/code&gt; function, in the same file. The &lt;code&gt;pull&lt;/code&gt; request doesn&amp;rsquo;t go only to the host: it goes out signed to every connected phone, which will matter in the section about the mesh.&lt;/p&gt;
&lt;p&gt;The full cycle, when Maria plays a card, including the signature covered in the next section:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://luizschons.com/images/posts/how-ito-works/host-en.svg" alt="Sequence diagram between guest and host. 1: the guest sends act, “I played my card”. 2: the host applies the rule, the version goes from 7 to 8, and it signs with the private key. 3: it sends state, version 8, with the signature. 4: the guest checks the signature with the public key pinned by the invite link’s fingerprint. 5: the guest replies ack with the version and the hash. 6: every 2 seconds, the host sends tick with version and hash. 7: if the hash doesn’t match, the guest sends pull. 8: the host resends the signed state. At the bottom, in red: a state without a valid signature or with an old version is dropped" loading="lazy" /&gt;&lt;/p&gt;
&lt;p&gt;This fixes lost messages without anyone noticing. If the state with Maria&amp;rsquo;s card gets lost on its way to some phone, on the next &lt;code&gt;tick&lt;/code&gt; that phone notices the difference and asks again.&lt;/p&gt;
&lt;p&gt;It isn&amp;rsquo;t a fancy consensus algorithm (the kind that gets several machines to agree without a boss). It&amp;rsquo;s one source of truth and a periodic check. For a game among friends, it&amp;rsquo;s exactly what&amp;rsquo;s needed.&lt;/p&gt;
&lt;p&gt;You can see the difference in roles on screen. In the same round, captured in the lab, the host has the &amp;ldquo;Revelar nessa ordem&amp;rdquo; (reveal in this order) button and can change the theme; the guest only sees a note saying that, once everyone agrees, João reveals:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://luizschons.com/images/posts/how-ito-works/ito-partida-anfitriao-convidado.webp" alt="Two real screenshots of the same Ito round, side by side, with the interface in Portuguese. On the left, the host’s screen, João: the theme “Programas de TV de domingo” (Sunday TV shows), from 1, “sono” (boring), to 100, “imperdível” (must-watch), the “Mudar tema” (change theme) button, the face-down card and the red “Revelar nessa ordem” (reveal in this order) button. On the right, the guest’s screen, Maria: the same theme and the same round 1 of 5, the face-down card and, instead of the button, the note “Quando todos concordarem, João revela” (when everyone agrees, João reveals)" loading="lazy" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In short:&lt;/strong&gt; only the host changes the state. Guests request actions, receive the versioned state and, every 2 seconds, check that they&amp;rsquo;re up to date.&lt;/p&gt;
&lt;h2 data-hextra-search-id="nobody-impersonates-the-host-signatures"&gt;Nobody impersonates the host: signatures&lt;span class="hx:absolute hx:-mt-20" id="nobody-impersonates-the-host-signatures"&gt;&lt;/span&gt;
&lt;a href="#nobody-impersonates-the-host-signatures" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;If the host is the truth, what stops someone from sending a fake state saying &amp;ldquo;I&amp;rsquo;m the host&amp;rdquo;? A &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Signature/Security" target="_blank" rel="noopener"&gt;&lt;strong&gt;digital signature&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The idea, without the math, uses a key pair (this is &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Public-key_cryptography" target="_blank" rel="noopener"&gt;public-key cryptography&lt;/a&gt;):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;private key&lt;/strong&gt; is a stamp only you have, and it never leaves the device.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;public key&lt;/strong&gt; is a copy of the stamp&amp;rsquo;s design. Anyone can use it to check whether a document was stamped by you, but nobody can stamp with it.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The first time it opens the game, each phone generates its key pair using &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/sign" target="_blank" rel="noopener"&gt;WebCrypto&lt;/a&gt;, the cryptography API built into the browser, available only on secure pages served over HTTPS (the code is in &lt;a href="https://github.com/sschonss/ito/blob/main/js/crypto.js" target="_blank" rel="noopener"&gt;js/crypto.js&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;The key type is &lt;strong&gt;ECDSA P-256&lt;/strong&gt;. ECDSA (Elliptic Curve Digital Signature Algorithm) is a signature algorithm based on elliptic curves, and P-256 is the curve used. It&amp;rsquo;s the same algorithm the server uses to stamp each send in &lt;a href="https://luizschons.com/posts/how-web-push-works/"&gt;Web Push&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In the game, it works like this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The host stamps (signs) every state, and everyone checks it.&lt;/li&gt;
&lt;li&gt;The state carries the room owner&amp;rsquo;s public key, and the invite link carries its &lt;strong&gt;fingerprint&lt;/strong&gt; (a short digest of the key). So Maria, who joined through the invite, already knows which stamp to expect.&lt;/li&gt;
&lt;li&gt;Each player&amp;rsquo;s introduction when joining the room (the &lt;code&gt;hello&lt;/code&gt; message) is signed too, so nobody can take someone else&amp;rsquo;s seat.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The project itself is clear about the limit: this protects against a fake host, &lt;strong&gt;not&lt;/strong&gt; against someone already in the room. Since cards are computed on the phone, someone who knows how to inspect the code in the browser could find out the numbers.&lt;/p&gt;
&lt;p&gt;Preventing that would require a server holding the cards. For a game among friends, it&amp;rsquo;s an acceptable trade-off.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In short:&lt;/strong&gt; every state carries the host&amp;rsquo;s stamp, and the invite says which stamp to expect. A fake state fails the check.&lt;/p&gt;
&lt;h2 data-hextra-search-id="when-not-everyone-can-reach-the-host-the-mesh"&gt;When not everyone can reach the host: the mesh&lt;span class="hx:absolute hx:-mt-20" id="when-not-everyone-can-reach-the-host-the-mesh"&gt;&lt;/span&gt;
&lt;a href="#when-not-everyone-can-reach-the-host-the-mesh" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;So far, the story assumed the host was connected directly to each guest. In practice, not every pair of phones can open a channel: the hard NATs and UDP-blocking networks from the first part of the article apply to each pair separately.&lt;/p&gt;
&lt;p&gt;Imagine a third player, Pedro, joins the room. João (the host) might have a channel to Maria, Maria might have a channel to Pedro, and Pedro might have no channel to João at all.&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s why Ito works as a &lt;strong&gt;mesh&lt;/strong&gt;: a network in which each phone connects to whoever it can, and messages hop from one to the next until they arrive. It&amp;rsquo;s like passing a note in class, from desk to desk.&lt;/p&gt;
&lt;p&gt;The host is still the only source of truth and still signs the state. What changes is the route: whoever receives a signed state newer than the one they had forwards the same packet to the phones connected to them.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://luizschons.com/images/posts/how-ito-works/mesh-en.svg" alt="Sequence diagram with three columns: João, the host; Maria, with a channel to both João and Pedro; and Pedro, with no direct channel to João. 1: João sends the state at version 12, signed, and Maria checks it and accepts because 12 is greater than 11. 2: Maria forwards the same signed packet, and Pedro checks João’s signature. 3, in red: version 12 arrives again through the other network and Maria drops it without forwarding. 4: Pedro sends a hint signed by him, with an id. 5: Maria forwards the action untouched and João applies it once, moving to version 13. 6 and 7: state 13 goes from João to Maria and from Maria to Pedro. Pedro’s screen shows “connected via Maria”. At the bottom: whoever is in the middle only forwards and cannot change anything; and, in red, the limit: if Pedro has no channel to anyone in the room, there is no path to forward through, and TURN is what solves it" loading="lazy" /&gt;&lt;/p&gt;
&lt;h3 data-hextra-search-id="the-state-going-out-from-joão-to-maria-and-from-maria-to-pedro"&gt;The state going out: from João to Maria, and from Maria to Pedro&lt;span class="hx:absolute hx:-mt-20" id="the-state-going-out-from-joão-to-maria-and-from-maria-to-pedro"&gt;&lt;/span&gt;
&lt;a href="#the-state-going-out-from-jo%c3%a3o-to-maria-and-from-maria-to-pedro" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;In the diagram&amp;rsquo;s example, João applies a move and sends the state at version 12, signed. Maria checks the signature, sees that 12 is greater than the 11 she had, accepts it and forwards the packet &lt;strong&gt;exactly as it arrived&lt;/strong&gt;, with João&amp;rsquo;s signature.&lt;/p&gt;
&lt;p&gt;Pedro runs the same check with João&amp;rsquo;s public key, not Maria&amp;rsquo;s. For him, it doesn&amp;rsquo;t matter which way the state came: the stamp is the host&amp;rsquo;s.&lt;/p&gt;
&lt;p&gt;Two rules hold this together:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The version sits inside the signed part.&lt;/strong&gt; &lt;code&gt;ver&lt;/code&gt; is the counter that grows with every state change, as in the section about the host. Since it&amp;rsquo;s part of what João signed, nobody in the middle can swap 12 for 99 without breaking the signature.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Only a strictly greater version is forwarded.&lt;/strong&gt; If version 12 arrives again (through the other signaling network, or back from Pedro himself), it isn&amp;rsquo;t greater than the 12 Maria has already seen, so it isn&amp;rsquo;t forwarded.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The second rule prevents two problems:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;loop&lt;/strong&gt;, where a message keeps going around between Maria and Pedro forever.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;replay&lt;/strong&gt;, where someone keeps an old, genuine, properly signed state and sends it again later to rewind the game. The old signature is still valid, but the old version doesn&amp;rsquo;t get through.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Because the game is served over HTTPS, the browser makes WebCrypto available, and so every state is signed (on a page without HTTPS, the code would carry on without signing). Whoever is in the middle can&amp;rsquo;t change a card, a point or the order: any change invalidates the stamp, and the state is dropped.&lt;/p&gt;
&lt;h3 data-hextra-search-id="actions-coming-back-the-same-way"&gt;Actions coming back the same way&lt;span class="hx:absolute hx:-mt-20" id="actions-coming-back-the-same-way"&gt;&lt;/span&gt;
&lt;a href="#actions-coming-back-the-same-way" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;The return path mirrors this. When Pedro gives a hint, plays his card, rearranges the order, votes, changes his name, leaves the room or writes in the chat, the request:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;goes out signed with &lt;strong&gt;Pedro&amp;rsquo;s&lt;/strong&gt; key;&lt;/li&gt;
&lt;li&gt;carries an &lt;code&gt;id&lt;/code&gt;, a unique identifier for that request.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Maria checks the signature with Pedro&amp;rsquo;s key, which she knows because the state&amp;rsquo;s player list carries each player&amp;rsquo;s public key. Then she forwards it to João without touching anything.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;id&lt;/code&gt; deals with duplicates: in a mesh, the same request can arrive through more than one path. João applies each &lt;code&gt;id&lt;/code&gt; only once, so Pedro&amp;rsquo;s hint never counts twice. And the signature stops Maria from inventing a move in Pedro&amp;rsquo;s name or swapping his hint for another one.&lt;/p&gt;
&lt;p&gt;Pedro&amp;rsquo;s screen shows a discreet note, &amp;ldquo;conectado via Maria&amp;rdquo; (connected via Maria), so he knows he&amp;rsquo;s playing through someone else. And the warning that the host dropped only shows up if that indirect path disappears too: as long as João&amp;rsquo;s &lt;code&gt;tick&lt;/code&gt; keeps arriving through Maria, nobody takes his place.&lt;/p&gt;
&lt;p&gt;To see the code: forwarding the state (&lt;code&gt;spreadState&lt;/code&gt;) and the actions lives in &lt;a href="https://github.com/sschonss/ito/blob/main/js/net.js" target="_blank" rel="noopener"&gt;js/net.js&lt;/a&gt;, signing each request (&lt;code&gt;seal&lt;/code&gt;) lives in &lt;a href="https://github.com/sschonss/ito/blob/main/js/crypto.js" target="_blank" rel="noopener"&gt;js/crypto.js&lt;/a&gt;, and the full design of the mesh is in &lt;a href="https://github.com/sschonss/ito/blob/main/docs/p2p.md" target="_blank" rel="noopener"&gt;docs/p2p.md&lt;/a&gt; (in Portuguese), in the &amp;ldquo;Malha&amp;rdquo; section.&lt;/p&gt;
&lt;h3 data-hextra-search-id="what-the-mesh-doesnt-solve"&gt;What the mesh doesn&amp;rsquo;t solve&lt;span class="hx:absolute hx:-mt-20" id="what-the-mesh-doesnt-solve"&gt;&lt;/span&gt;
&lt;a href="#what-the-mesh-doesnt-solve" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;The mesh only helps someone who has a channel to &lt;strong&gt;someone&lt;/strong&gt; in the room. If Pedro can&amp;rsquo;t open a channel to anyone, there&amp;rsquo;s no path to forward through, and he stays out.&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s the case of hard NATs and UDP-blocking networks, and what solves it is Cloudflare&amp;rsquo;s TURN, covered at the start: it gives Pedro a path to at least one of the other phones. One complements the other; neither replaces the other.&lt;/p&gt;
&lt;p&gt;And Maria, even though she can&amp;rsquo;t forge or change anything, can still simply stop forwarding. In that case Pedro gets no news, as if the connection had dropped.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In short:&lt;/strong&gt; whoever can&amp;rsquo;t reach the host gets the state secondhand. Whoever is in the middle can only forward, because the signature and the version block any change.&lt;/p&gt;
&lt;h2 data-hextra-search-id="what-if-the-host-drops"&gt;What if the host drops?&lt;span class="hx:absolute hx:-mt-20" id="what-if-the-host-drops"&gt;&lt;/span&gt;
&lt;a href="#what-if-the-host-drops" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;The host is the source of truth, so it&amp;rsquo;s also a single point of failure. Imagine João steps into an elevator and his phone loses signal.&lt;/p&gt;
&lt;p&gt;If the host&amp;rsquo;s phone loses its connection (on both networks) and doesn&amp;rsquo;t come back within about 5 seconds, the connected player with the lowest seat number at the table becomes the &lt;strong&gt;provisional host&lt;/strong&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Only someone who received the current state in this session takes over.&lt;/li&gt;
&lt;li&gt;They bump the version (&lt;code&gt;ver + 1&lt;/code&gt;) so everyone recognizes the new state.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When João, the room owner, comes back, he waits a moment to get the newest state from the provisional host and &lt;strong&gt;takes over again&lt;/strong&gt;. The game continues where it stopped, without losing moves.&lt;/p&gt;
&lt;p&gt;Signatures cover this case too: the provisional host&amp;rsquo;s state is only accepted while the owner is away, and with a key everyone already knew. The host handover lives in the &lt;code&gt;considerHostLost&lt;/code&gt; and &lt;code&gt;finishReclaim&lt;/code&gt; functions, in &lt;a href="https://github.com/sschonss/ito/blob/main/js/net.js" target="_blank" rel="noopener"&gt;js/net.js&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In short:&lt;/strong&gt; if the host disappears, another player holds the game until João is back, and nobody loses a move.&lt;/p&gt;
&lt;h2 data-hextra-search-id="how-to-test-something-that-depends-on-public-networks"&gt;How to test something that depends on public networks&lt;span class="hx:absolute hx:-mt-20" id="how-to-test-something-that-depends-on-public-networks"&gt;&lt;/span&gt;
&lt;a href="#how-to-test-something-that-depends-on-public-networks" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Depending on third-party relays and brokers is great until the day one of them changes. That&amp;rsquo;s why Ito has two kinds of tests:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;End-to-end tests with a fake relay:&lt;/strong&gt; tests that use the whole app the way a person would. They open several &amp;ldquo;phones&amp;rdquo; in a browser driven by &lt;a href="https://playwright.dev/" target="_blank" rel="noopener"&gt;Playwright&lt;/a&gt; (a tool that automates browsers) and swap the connection library for a fake one that imitates both networks inside the test itself. Fast, and no internet dependency.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A daily test on the real networks:&lt;/strong&gt; a &lt;a href="https://github.com/features/actions" target="_blank" rel="noopener"&gt;GitHub Actions&lt;/a&gt; workflow (an automated routine) runs every day, connects two browsers over the real internet and plays a round in three scenarios: Nostr only, MQTT only and both networks together. If a public relay or broker changes, the test warns me before anyone tries to play.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 data-hextra-search-id="limits-and-what-i-learned"&gt;Limits and what I learned&lt;span class="hx:absolute hx:-mt-20" id="limits-and-what-i-learned"&gt;&lt;/span&gt;
&lt;a href="#limits-and-what-i-learned" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;&amp;ldquo;No server&amp;rdquo; needs an asterisk: &lt;strong&gt;there is no central server for the match&lt;/strong&gt;. There are still Nostr relays, MQTT brokers, STUN servers, Cloudflare&amp;rsquo;s TURN (with my Worker) and the &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/CDN" target="_blank" rel="noopener"&gt;CDNs&lt;/a&gt; (networks of servers that deliver files) the library loads from.&lt;/p&gt;
&lt;p&gt;All of them are third parties and can go down. The two networks and the fallback addresses reduce the risk but don&amp;rsquo;t eliminate it. The game also needs internet for the first connection and, as I said, isn&amp;rsquo;t cheat-proof among people already in the room.&lt;/p&gt;
&lt;p&gt;What I take from the lab:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The browser knows a lot more than I imagined:&lt;/strong&gt; encrypted P2P connections and real cryptography, with nothing to install.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sometimes the best way to sync is not to send anything at all:&lt;/strong&gt; the deterministic deck removed a whole category of problems.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;One source of truth with versions and a check goes a long way:&lt;/strong&gt; before reaching for a consensus algorithm, ask whether a boss and a check every 2 seconds are enough.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Be honest about dependencies:&lt;/strong&gt; naming what belongs to third parties helps decide what to test every day.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Open &lt;a href="https://sschonss.github.io/ito/" target="_blank" rel="noopener"&gt;Ito&lt;/a&gt;, create a room and call your friends: everything here really happens on your phone. And if you haven&amp;rsquo;t read it yet, the context for why I built this is in &lt;a href="https://luizschons.com/posts/personal-projects-as-a-lab/"&gt;Programming is still fun&lt;/a&gt;. If you&amp;rsquo;ve played with WebRTC or have an idea for a P2P game, tell me in the comments.&lt;/p&gt;
&lt;h2 data-hextra-search-id="glossary"&gt;Quick glossary&lt;span class="hx:absolute hx:-mt-20" id="glossary"&gt;&lt;/span&gt;
&lt;a href="#glossary" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Every term in the article, one line each, in the order they appear:&lt;/p&gt;
&lt;div class="article-table-wrap"&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Term&lt;/th&gt;
&lt;th&gt;In one sentence&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;PWA&lt;/td&gt;
&lt;td&gt;A website you can install and open like an app.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WebRTC&lt;/td&gt;
&lt;td&gt;Browser technology for direct, real-time communication, the same one behind video calls.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Data channel&lt;/td&gt;
&lt;td&gt;WebRTC&amp;rsquo;s &amp;ldquo;pipe&amp;rdquo; for arbitrary data, such as moves.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;P2P&lt;/td&gt;
&lt;td&gt;Each device talks directly to the others, with no central server in the middle.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DTLS / TLS&lt;/td&gt;
&lt;td&gt;The channel&amp;rsquo;s encryption; TLS is the HTTPS padlock, and DTLS is the version for this kind of connection.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Public / private IP&lt;/td&gt;
&lt;td&gt;A device&amp;rsquo;s address; the public one works across the whole internet, the private one only at home.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Port&lt;/td&gt;
&lt;td&gt;An extra number next to the address, like the apartment number on an envelope.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;NAT&lt;/td&gt;
&lt;td&gt;The router as doorman: one public address for the whole home, and only replies get in.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CGNAT&lt;/td&gt;
&lt;td&gt;The carrier&amp;rsquo;s NAT, with thousands of customers behind the same public address.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;UDP&lt;/td&gt;
&lt;td&gt;A fast packet type with no delivery confirmation, WebRTC&amp;rsquo;s favorite.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ICE&lt;/td&gt;
&lt;td&gt;The process that gathers possible addresses and tests which path works.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ICE candidate&lt;/td&gt;
&lt;td&gt;An address where the phone might be reachable (&lt;code&gt;host&lt;/code&gt;, &lt;code&gt;srflx&lt;/code&gt; or &lt;code&gt;relay&lt;/code&gt;).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;STUN&lt;/td&gt;
&lt;td&gt;A server that answers &amp;ldquo;this is how you look from outside&amp;rdquo;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hole punching&lt;/td&gt;
&lt;td&gt;Both sides send packets at the same time to open a path through the NATs.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TURN&lt;/td&gt;
&lt;td&gt;A server that relays the encrypted data when the direct path doesn&amp;rsquo;t open.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Signaling&lt;/td&gt;
&lt;td&gt;The exchange of notes before the direct channel exists.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SDP&lt;/td&gt;
&lt;td&gt;The connection&amp;rsquo;s &amp;ldquo;spec sheet&amp;rdquo;, traded as an offer and an answer.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Nostr relay / MQTT broker&lt;/td&gt;
&lt;td&gt;Public servers Ito uses as a bulletin board for signaling.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hash&lt;/td&gt;
&lt;td&gt;A short fingerprint of a text; any change to the text changes the hash.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Idempotent&lt;/td&gt;
&lt;td&gt;Receiving the same message twice is the same as receiving it once.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Seed&lt;/td&gt;
&lt;td&gt;The starting text of a pseudorandom generator; same seed, same numbers.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Host / guest&lt;/td&gt;
&lt;td&gt;Whoever created the room and owns the state / whoever joined and requests actions.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;act&lt;/code&gt;, &lt;code&gt;state&lt;/code&gt;, &lt;code&gt;ack&lt;/code&gt;, &lt;code&gt;tick&lt;/code&gt;, &lt;code&gt;pull&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Action request, full state, acknowledgment, check every 2 seconds and &amp;ldquo;send it again&amp;rdquo;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Digital signature&lt;/td&gt;
&lt;td&gt;A stamp made with the private key and checked with the public key.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ECDSA P-256&lt;/td&gt;
&lt;td&gt;The algorithm and curve used for Ito&amp;rsquo;s signatures.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mesh&lt;/td&gt;
&lt;td&gt;Each phone connects to whoever it can, and messages get passed along.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Replay&lt;/td&gt;
&lt;td&gt;Resending an old, genuine message to rewind time; the version blocks it.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CDN&lt;/td&gt;
&lt;td&gt;A network of servers that delivers files, such as the connection library.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;</description></item><item><title>Web Push under the hood: how a notification arrives with the tab closed</title><link>https://luizschons.com/posts/how-web-push-works/</link><pubDate>Tue, 03 Nov 2026 00:00:00 -0300</pubDate><guid>https://luizschons.com/posts/how-web-push-works/</guid><description>
&lt;p&gt;Almost everyone has received a website notification with the tab closed. Behind it there are three players: your server, a delivery service that belongs to the browser, and a piece of JavaScript that wakes up on its own. And a detail I find beautiful: the service in the middle delivers the message without being able to read it. In this article I walk through that path with real output from a lab run in Chrome, first in a regular tab and then with the site installed as an app (a PWA).&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s a companion to &lt;a href="https://luizschons.com/posts/personal-projects-as-a-lab/"&gt;Programming is still fun&lt;/a&gt;, about the joy of building things out of curiosity in the AI era. The lab is &lt;a href="https://github.com/sschonss/lab-web-push-vapid" target="_blank" rel="noopener"&gt;lab-web-push-vapid&lt;/a&gt;: a minimal Node.js server, a page, a manifest and a service worker. Everything here was measured on October 28, 2026, with Chrome 156 on Linux and the &lt;a href="https://github.com/web-push-libs/web-push" target="_blank" rel="noopener"&gt;web-push&lt;/a&gt; library 3.6.7. Where something was simulated or not tested, I say so.&lt;/p&gt;
&lt;h2 data-hextra-search-id="the-problem-notifying-someone-who-isnt-looking"&gt;The problem: notifying someone who isn&amp;rsquo;t looking&lt;span class="hx:absolute hx:-mt-20" id="the-problem-notifying-someone-who-isnt-looking"&gt;&lt;/span&gt;
&lt;a href="#the-problem-notifying-someone-who-isnt-looking" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;With the tab open, notifying is easy: the page keeps a connection to the server. With the tab closed, there is no page. And the server can&amp;rsquo;t just &amp;ldquo;call&amp;rdquo; the phone: the device has no fixed address, sits behind routers and carriers, and keeping a connection open for every site would waste battery.&lt;/p&gt;
&lt;p&gt;The web&amp;rsquo;s answer is the same as for mobile apps: &lt;strong&gt;a single channel per browser&lt;/strong&gt;, through which messages from every site arrive. It&amp;rsquo;s like a post office box: the post office holds the letter and hands it over when you stop by.&lt;/p&gt;
&lt;h2 data-hextra-search-id="the-three-players"&gt;The three players&lt;span class="hx:absolute hx:-mt-20" id="the-three-players"&gt;&lt;/span&gt;
&lt;a href="#the-three-players" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;The application server:&lt;/strong&gt; your backend. It stores the subscriptions and decides when to notify.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The push service:&lt;/strong&gt; the browser&amp;rsquo;s delivery service. In Chrome it&amp;rsquo;s FCM (Firebase Cloud Messaging, from Google), in Firefox it&amp;rsquo;s Mozilla&amp;rsquo;s, in Safari it&amp;rsquo;s Apple&amp;rsquo;s. The browser chooses, not you.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The service worker:&lt;/strong&gt; JavaScript that the site registers in the browser and that lives outside the tab (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API" target="_blank" rel="noopener"&gt;MDN&lt;/a&gt;). The browser wakes it up when a message arrives, even with no tab of the site open.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The protocol between the server and the push service is plain HTTP, defined in &lt;a href="https://datatracker.ietf.org/doc/html/rfc8030" target="_blank" rel="noopener"&gt;RFC 8030&lt;/a&gt;: a &lt;code&gt;POST&lt;/code&gt; to a URL. The diagram below shows the whole path.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://luizschons.com/images/posts/how-web-push-works/flow-en.svg" alt="Web Push flow. 1: the page calls pushManager.subscribe with the VAPID public key. 2: the push service returns endpoint, p256dh and auth. 3: the page sends the subscription to the server. The tab may close. 4: the server POSTs to the endpoint with the VAPID JWT and the encrypted body. 5: the push service answers 201, or 410 if the subscription is dead, and then the server deletes it. 6: the push service delivers to the service worker, which wakes up. 7: the service worker calls showNotification" loading="lazy" /&gt;&lt;/p&gt;
&lt;h2 data-hextra-search-id="pwa-when-the-site-becomes-an-app"&gt;PWA: when the site becomes an app&lt;span class="hx:absolute hx:-mt-20" id="pwa-when-the-site-becomes-an-app"&gt;&lt;/span&gt;
&lt;a href="#pwa-when-the-site-becomes-an-app" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;A PWA (Progressive Web App) is not a framework. It&amp;rsquo;s a regular site with two extra pieces that let you &lt;strong&gt;install&lt;/strong&gt; it as an app (&lt;a href="https://web.dev/learn/pwa/" target="_blank" rel="noopener"&gt;web.dev&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps" target="_blank" rel="noopener"&gt;MDN&lt;/a&gt;):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The manifest:&lt;/strong&gt; a JSON file (&lt;code&gt;manifest.webmanifest&lt;/code&gt;) with the app&amp;rsquo;s &amp;ldquo;ID card&amp;rdquo;: name, icons, start URL and how it opens (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Manifest" target="_blank" rel="noopener"&gt;MDN&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The service worker:&lt;/strong&gt; the same one from Web Push. It gives the app what a page doesn&amp;rsquo;t have: the ability to run with no tab open, receive push and work offline.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A minimal manifest looks like this (an illustrative example, not the lab&amp;rsquo;s file):&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-json" data-lang="json"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;name&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Lab Web Push com VAPID&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;start_url&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;/&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;display&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;standalone&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;icons&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nt"&gt;&amp;#34;src&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;/icon-192.png&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;&amp;#34;sizes&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;192x192&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;&amp;#34;type&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;image/png&amp;#34;&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nt"&gt;&amp;#34;src&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;/icon-512.png&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;&amp;#34;sizes&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;512x512&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;&amp;#34;type&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;image/png&amp;#34;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Installing.&lt;/strong&gt; When the site meets &lt;a href="https://web.dev/articles/install-criteria" target="_blank" rel="noopener"&gt;Chrome&amp;rsquo;s criteria&lt;/a&gt; (HTTPS, a manifest with a name, 192 and 512 px icons, &lt;code&gt;start_url&lt;/code&gt; and a &lt;code&gt;display&lt;/code&gt; such as &lt;code&gt;standalone&lt;/code&gt;, plus a bit of user interaction with the page), the browser fires the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeinstallprompt_event" target="_blank" rel="noopener"&gt;&lt;code&gt;beforeinstallprompt&lt;/code&gt;&lt;/a&gt; event. The site keeps that event and shows its own install button; on click, it calls &lt;code&gt;event.prompt()&lt;/code&gt; and Chrome opens the native dialog (&lt;a href="https://web.dev/articles/customize-install" target="_blank" rel="noopener"&gt;web.dev&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Standalone.&lt;/strong&gt; Once installed, the app opens in its own window, with no address bar and an icon in the system menu. The page finds out through the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@media/display-mode" target="_blank" rel="noopener"&gt;&lt;code&gt;display-mode&lt;/code&gt;&lt;/a&gt; media query: &lt;code&gt;matchMedia('(display-mode: standalone)')&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Why does this matter for push? On desktop, Chrome delivers push to a regular tab too. But on iPhone and iPad, since iOS 16.4, &lt;a href="https://webkit.org/blog/13878/web-push-for-web-apps-on-ios-and-ipados/" target="_blank" rel="noopener"&gt;Web Push only works for web apps added to the Home Screen&lt;/a&gt;. And, as the lab showed, clicking the notification can open the app&amp;rsquo;s window, not a tab.&lt;/p&gt;
&lt;p&gt;In the lab, Chrome read the manifest with no errors, the list of installability errors (&lt;code&gt;Page.getInstallabilityErrors&lt;/code&gt;, in the DevTools Protocol) came back empty, and &lt;code&gt;beforeinstallprompt&lt;/code&gt; fired. &lt;code&gt;prompt()&lt;/code&gt; opened the &amp;ldquo;Install app&amp;rdquo; dialog. One detail that tripped up the test: initial focus is on &lt;strong&gt;Cancel&lt;/strong&gt;, the blue button. In one run the click landed on it and nothing was installed; the run that counts clicked &lt;strong&gt;Install&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://luizschons.com/images/posts/how-web-push-works/webpush-pwa-install.webp" alt="The lab page in Chrome with the native Install app dialog on top: name Lab Web Push com VAPID, origin 127.0.0.1:8788, Cancel button highlighted, and Install. The page reads Modo de exibição: browser" loading="lazy" /&gt;&lt;/p&gt;
&lt;p&gt;Once installed, the app opened in a window with no address bar, with &lt;code&gt;matchMedia('(display-mode: standalone)')&lt;/code&gt; true. The lab ran on &lt;code&gt;http://127.0.0.1&lt;/code&gt;, which the browser treats as a secure origin; in production, it&amp;rsquo;s HTTPS.&lt;/p&gt;
&lt;h2 data-hextra-search-id="subscribing-the-browser-gives-you-an-address"&gt;Subscribing: the browser gives you an address&lt;span class="hx:absolute hx:-mt-20" id="subscribing-the-browser-gives-you-an-address"&gt;&lt;/span&gt;
&lt;a href="#subscribing-the-browser-gives-you-an-address" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;It all starts with a click on &lt;strong&gt;Ativar notificações&lt;/strong&gt; (&amp;ldquo;Enable notifications&amp;rdquo;): the browser only asks for permission in response to a user gesture. If the user blocks it, the site can&amp;rsquo;t ask again.&lt;/p&gt;
&lt;p&gt;With permission granted, the page asks the browser for a subscription (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/PushManager/subscribe" target="_blank" rel="noopener"&gt;&lt;code&gt;PushManager.subscribe()&lt;/code&gt;&lt;/a&gt;):&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-javascript" data-lang="javascript"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kr"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;subscription&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kr"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;registration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pushManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;userVisibleOnly&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// every push becomes a visible notification
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;applicationServerKey&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;urlBase64ToUint8Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="c1"&gt;// the server&amp;#39;s VAPID public key
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;});&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;userVisibleOnly: true&lt;/code&gt; is a promise Chrome requires: no silent push. The &lt;code&gt;applicationServerKey&lt;/code&gt; is the server&amp;rsquo;s &lt;strong&gt;VAPID public key&lt;/strong&gt;. The browser talks to the push service and returns three things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;endpoint&lt;/code&gt;:&lt;/strong&gt; a unique URL on the push service, the &amp;ldquo;mailbox address&amp;rdquo;. In the lab: &lt;code&gt;https://fcm.googleapis.com/fcm/send/dHcP…E3xQ&lt;/code&gt; (masked: whoever has this URL and the private key can send push).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;p256dh&lt;/code&gt;:&lt;/strong&gt; that browser&amp;rsquo;s public encryption key (65 bytes, measured in the lab).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;auth&lt;/code&gt;:&lt;/strong&gt; a 16-byte secret, also measured.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The page sends this JSON to the server, which stores it. From here on, the tab can close.&lt;/p&gt;
&lt;h2 data-hextra-search-id="sending-sign-and-encrypt"&gt;Sending: sign and encrypt&lt;span class="hx:absolute hx:-mt-20" id="sending-sign-and-encrypt"&gt;&lt;/span&gt;
&lt;a href="#sending-sign-and-encrypt" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;To notify, the server makes a &lt;code&gt;POST&lt;/code&gt; to the &lt;code&gt;endpoint&lt;/code&gt;. This is the real request the Node process wrote to FCM in the lab:&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;POST /fcm/send/dHcP…E3xQ
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;host: fcm.googleapis.com
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ttl: 3600
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;urgency: high
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;topic: lab
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;content-type: application/octet-stream
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;content-encoding: aes128gcm
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;content-length: 182
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;authorization: vapid t=eyJ0eXAiOiJK…Y1qM-A, k=BPTww8…HZro&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;TTL&lt;/code&gt;&lt;/strong&gt; says how long the push service keeps the message if the device is offline (here, one hour); &lt;strong&gt;&lt;code&gt;Urgency&lt;/code&gt;&lt;/strong&gt; helps the device decide whether it&amp;rsquo;s worth waking up now; &lt;strong&gt;&lt;code&gt;Topic&lt;/code&gt;&lt;/strong&gt; makes a new message replace an older undelivered one. &lt;code&gt;Authorization&lt;/code&gt; and &lt;code&gt;Content-Encoding&lt;/code&gt; are the two proofs that make Web Push work.&lt;/p&gt;
&lt;h3 data-hextra-search-id="proof-1-who-is-sending-vapid"&gt;Proof 1: who is sending (VAPID)&lt;span class="hx:absolute hx:-mt-20" id="proof-1-who-is-sending-vapid"&gt;&lt;/span&gt;
&lt;a href="#proof-1-who-is-sending-vapid" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href="https://datatracker.ietf.org/doc/html/rfc8292" target="_blank" rel="noopener"&gt;VAPID&lt;/a&gt; (Voluntary Application Server Identification, RFC 8292) is how the server identifies itself. The public key was handed to the browser at subscription time; the private key never leaves the server. On every send, the server builds a &lt;strong&gt;JWT&lt;/strong&gt; (a signed JSON ticket) and signs it with &lt;strong&gt;ES256&lt;/strong&gt; (ECDSA on the P-256 curve). Think of a rubber stamp: only the server has the stamp, and everyone has its design to check against. The JWT goes in &lt;code&gt;t=&lt;/code&gt;, and the public key in &lt;code&gt;k=&lt;/code&gt;. Decoded, the lab&amp;rsquo;s was:&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-json" data-lang="json"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;header&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nt"&gt;&amp;#34;typ&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;JWT&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;&amp;#34;alg&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;ES256&amp;#34;&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;payload&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;aud&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;https://fcm.googleapis.com&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;exp&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1793269014&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;sub&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;mailto:webpush-lab@luizschons.com&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;aud&lt;/code&gt;&lt;/strong&gt; is the push service&amp;rsquo;s origin; &lt;strong&gt;&lt;code&gt;exp&lt;/code&gt;&lt;/strong&gt;, 1793269014, is Oct 29 at 07:16 (BRT, UTC-3), &lt;strong&gt;12 hours&lt;/strong&gt; after the send (the RFC allows up to 24); &lt;strong&gt;&lt;code&gt;sub&lt;/code&gt;&lt;/strong&gt; is a contact for the server&amp;rsquo;s owner. Without the private key, nobody else can send push to that subscription, even if they find the &lt;code&gt;endpoint&lt;/code&gt;. In the lab, the signature was checked against the key in &lt;code&gt;k=&lt;/code&gt; and it matched.&lt;/p&gt;
&lt;h3 data-hextra-search-id="proof-2-only-the-browser-reads-message-encryption"&gt;Proof 2: only the browser reads (message encryption)&lt;span class="hx:absolute hx:-mt-20" id="proof-2-only-the-browser-reads-message-encryption"&gt;&lt;/span&gt;
&lt;a href="#proof-2-only-the-browser-reads-message-encryption" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;The body is the notification JSON &lt;strong&gt;encrypted&lt;/strong&gt; for that browser, as &lt;a href="https://datatracker.ietf.org/doc/html/rfc8291" target="_blank" rel="noopener"&gt;RFC 8291&lt;/a&gt; requires, in the &lt;code&gt;aes128gcm&lt;/code&gt; format from &lt;a href="https://datatracker.ietf.org/doc/html/rfc8188" target="_blank" rel="noopener"&gt;RFC 8188&lt;/a&gt;. In plain words:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The server generates a throwaway key pair and combines it with &lt;code&gt;p256dh&lt;/code&gt; (&lt;strong&gt;ECDH&lt;/strong&gt;: two sides reach the same secret without sending it).&lt;/li&gt;
&lt;li&gt;It mixes that secret with &lt;code&gt;auth&lt;/code&gt; (&lt;strong&gt;HKDF&lt;/strong&gt;, a &amp;ldquo;blender&amp;rdquo; that produces a key of the right size).&lt;/li&gt;
&lt;li&gt;It encrypts with &lt;strong&gt;AES-128-GCM&lt;/strong&gt;, which encrypts the data and detects whether anyone tampered with it.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;In the lab, the server asked to encrypt &lt;code&gt;{&amp;quot;title&amp;quot;:&amp;quot;Lab Web Push&amp;quot;,&amp;quot;body&amp;quot;:&amp;quot;Disparo com a página ainda aberta.&amp;quot;,&amp;quot;url&amp;quot;:&amp;quot;/&amp;quot;}&lt;/code&gt; (&amp;ldquo;Sent with the page still open&amp;rdquo;), and what went over the wire to FCM was 182 bytes, starting like this (in base64):&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;up0IdDqUjddJJ6BRZBs3bgAAEABBBFVesIOZiJ6vLr15vPgvvmSHkXvqmQco4r67M4qgM4SSurodkhcr…&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The plaintext doesn&amp;rsquo;t appear inside those bytes. The service worker decrypted it and got back the same JSON, character for character.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://luizschons.com/images/posts/how-web-push-works/trust-en.svg" alt="The two proofs of Web Push. VAPID, a JWT signed with ES256, proves to the push service who is sending. Encryption with p256dh and auth, ECDH, HKDF and AES-128-GCM, makes sure only the browser reads. In the middle, the push service sees the endpoint, the headers and the encrypted bytes, but not the text" loading="lazy" /&gt;&lt;/p&gt;
&lt;p&gt;FCM answered &lt;code&gt;HTTP 201&lt;/code&gt; with an empty body. &lt;strong&gt;201 Created&lt;/strong&gt; means &amp;ldquo;received, will deliver&amp;rdquo;, not &amp;ldquo;the user saw it&amp;rdquo;.&lt;/p&gt;
&lt;h2 data-hextra-search-id="delivery-the-service-worker-wakes-up"&gt;Delivery: the service worker wakes up&lt;span class="hx:absolute hx:-mt-20" id="delivery-the-service-worker-wakes-up"&gt;&lt;/span&gt;
&lt;a href="#delivery-the-service-worker-wakes-up" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;When the message arrives, the browser wakes the service worker and fires the &lt;code&gt;push&lt;/code&gt; event. The lab&amp;rsquo;s handler:&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-javascript" data-lang="javascript"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;push&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="kr"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;readPayload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;waitUntil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;registration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;showNotification&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;tag&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;lab-web-push&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}));&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;});&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;waitUntil&lt;/code&gt; asks the browser not to go back to sleep before the notification is created. On click, another event, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/notificationclick_event" target="_blank" rel="noopener"&gt;&lt;code&gt;notificationclick&lt;/code&gt;&lt;/a&gt;, looks for a window of the site with &lt;code&gt;clients.matchAll()&lt;/code&gt;: if it finds one, it calls &lt;code&gt;focus()&lt;/code&gt;; if not, it opens the URL with &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Clients/openWindow" target="_blank" rel="noopener"&gt;&lt;code&gt;clients.openWindow()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In the first run, the regular tab was closed and the server sent another push. FCM answered 201, and the service worker, &lt;strong&gt;with no tab open&lt;/strong&gt;, returned &lt;code&gt;{&amp;quot;title&amp;quot;:&amp;quot;Prova no Chrome&amp;quot;,&amp;quot;body&amp;quot;:&amp;quot;Disparo com a aba fechada.&amp;quot;,&amp;quot;url&amp;quot;:&amp;quot;/&amp;quot;}&lt;/code&gt; (&amp;ldquo;Sent with the tab closed&amp;rdquo;). Chrome registered the notification, but no system popup appeared, and the click went untested. The PWA run closed both gaps.&lt;/p&gt;
&lt;h2 data-hextra-search-id="end-to-end-with-the-installed-app"&gt;End to end with the installed app&lt;span class="hx:absolute hx:-mt-20" id="end-to-end-with-the-installed-app"&gt;&lt;/span&gt;
&lt;a href="#end-to-end-with-the-installed-app" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;In the PWA run, the lab started a notification server (dunst) on the display, so the system notification would appear and could be clicked. With the app installed, permission granted and the subscription made, the test went through each window state (times in BRT, UTC-3, on the night of October 28):&lt;/p&gt;
&lt;div class="article-table-wrap"&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;App state&lt;/th&gt;
&lt;th&gt;FCM response&lt;/th&gt;
&lt;th&gt;What happened&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Foreground&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;410&lt;/strong&gt; at 23:29:31 and 23:29:35&lt;/td&gt;
&lt;td&gt;nothing shown; the server deleted the subscription&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Minimized&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;201&lt;/strong&gt; at 23:29:40&lt;/td&gt;
&lt;td&gt;the service worker read it, system notification appeared&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Window closed, Chrome running&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;201&lt;/strong&gt; at 23:29:42&lt;/td&gt;
&lt;td&gt;the service worker read it, notification appeared, click opened the app&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Chrome fully closed&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;201&lt;/strong&gt; at 23:29:46&lt;/td&gt;
&lt;td&gt;nothing until Chrome was reopened; then it arrived&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;With the window minimized, the service worker read &lt;code&gt;{&amp;quot;title&amp;quot;:&amp;quot;PWA minimizado&amp;quot;,&amp;quot;body&amp;quot;:&amp;quot;A janela do aplicativo foi minimizada.&amp;quot;,&amp;quot;url&amp;quot;:&amp;quot;/&amp;quot;}&lt;/code&gt; (&amp;ldquo;PWA minimized&amp;rdquo;, &amp;ldquo;The app window was minimized&amp;rdquo;) and the notification appeared on screen:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://luizschons.com/images/posts/how-web-push-works/webpush-pwa-notification.webp" alt="System notification with the lab’s bell icon, the title PWA minimizado, the origin 127.0.0.1:8788 and the text A janela do aplicativo foi minimizada" loading="lazy" /&gt;&lt;/p&gt;
&lt;p&gt;Next, the test closed the site&amp;rsquo;s windows and left the Chrome process alive. FCM answered 201, the service worker read &lt;code&gt;{&amp;quot;title&amp;quot;:&amp;quot;PWA com a janela fechada&amp;quot;,&amp;quot;body&amp;quot;:&amp;quot;A janela foi fechada. O Chrome segue aberto.&amp;quot;,&amp;quot;url&amp;quot;:&amp;quot;/&amp;quot;}&lt;/code&gt; (&amp;ldquo;The window was closed. Chrome is still open.&amp;rdquo;) and the notification appeared. Then came the click, through the notification server&amp;rsquo;s default action, with no event faked on the page. The service worker logged:&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-json" data-lang="json"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;url&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;http://127.0.0.1:8788/&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;action&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;openWindow&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;focused&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;opened&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;#34;clientCount&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;clientCount: 0&lt;/code&gt; means there was no window of the site open, so the code didn&amp;rsquo;t call &lt;code&gt;focus()&lt;/code&gt;: it called &lt;code&gt;clients.openWindow()&lt;/code&gt;, which returned success. And the window that appeared was &lt;strong&gt;the installed app&amp;rsquo;s&lt;/strong&gt;, with no address bar, in &lt;code&gt;display-mode: standalone&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://luizschons.com/images/posts/how-web-push-works/webpush-pwa-click-standalone.webp" alt="The installed app’s window opened by the notification click: title Lab Web Push com VAPID, no address bar, and the page showing Modo de exibição: standalone" loading="lazy" /&gt;&lt;/p&gt;
&lt;p&gt;(The line &amp;ldquo;O Chrome ainda não ofereceu a instalação&amp;rdquo;, &amp;ldquo;Chrome hasn&amp;rsquo;t offered installation yet&amp;rdquo;, is expected: an installed app doesn&amp;rsquo;t get &lt;code&gt;beforeinstallprompt&lt;/code&gt; again.)&lt;/p&gt;
&lt;p&gt;Finally, the test quit Chrome completely, with no process left, and sent one more push. FCM answered &lt;strong&gt;201&lt;/strong&gt;, but in the 15 seconds with Chrome dead nothing arrived. When the same profile was reopened, at 23:30:04, the service worker read the message and the notification appeared.&lt;/p&gt;
&lt;h2 data-hextra-search-id="when-things-go-wrong"&gt;When things go wrong&lt;span class="hx:absolute hx:-mt-20" id="when-things-go-wrong"&gt;&lt;/span&gt;
&lt;a href="#when-things-go-wrong" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;The subscription dies.&lt;/strong&gt; The user revokes permission, clears the site&amp;rsquo;s data or uninstalls the PWA. Then the push service answers &lt;strong&gt;404 or 410&lt;/strong&gt; (Gone), and the server should delete the subscription. In the lab, the page canceled the subscription in the browser (&lt;code&gt;subscription.unsubscribe()&lt;/code&gt;) without telling the server. The surprise: the send one second later &lt;strong&gt;still returned 201&lt;/strong&gt;. About a minute later, the same endpoint answered:&lt;/p&gt;
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code"&gt;
&lt;div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;HTTP 410
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;date: Wed, 28 Oct 2026 22:18:06 GMT
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;push subscription has unsubscribed or expired.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0"&gt;
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
aria-label="Copy code"
data-copied-label="Copied!"
&gt;
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4"&gt;&lt;/div&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The server deleted the record. The 410 is the guaranteed cleanup, but it isn&amp;rsquo;t instant, so if the page can tell the server when it unsubscribes, even better. There&amp;rsquo;s also the &lt;code&gt;pushsubscriptionchange&lt;/code&gt; event, but &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/pushsubscriptionchange_event" target="_blank" rel="noopener"&gt;MDN&lt;/a&gt; marks its support as limited, and the lab couldn&amp;rsquo;t tell whether it fired.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A 201 isn&amp;rsquo;t guaranteed, even for a new subscription.&lt;/strong&gt; In a second run in the regular tab, a freshly created subscription got 410 on the very first send. With the installed app in the foreground, both sends also got 410, with the same message, and nothing appeared. The only foreground notification observed was in a tab, before installation. The lab didn&amp;rsquo;t find the cause. A &lt;strong&gt;hypothesis&lt;/strong&gt;, not confirmed: the problem may lie in that subscription, not in the foreground, since the next subscription got 201 in every other state. But that subscription wasn&amp;rsquo;t tested in the foreground, so this remains open.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A closed browser is not a closed tab.&lt;/strong&gt; With Chrome quit, the push service accepts and stores the message, but the notification only appears when the browser comes back. If the &lt;code&gt;TTL&lt;/code&gt; expires first, it never arrives.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Incognito window.&lt;/strong&gt; Chrome refuses push in incognito mode, and the page only sees &lt;code&gt;Registration failed - permission denied&lt;/code&gt;, with no way to detect it beforehand.&lt;/p&gt;
&lt;h2 data-hextra-search-id="what-was-simulated-and-what-wasnt-tested"&gt;What was simulated and what wasn&amp;rsquo;t tested&lt;span class="hx:absolute hx:-mt-20" id="what-was-simulated-and-what-wasnt-tested"&gt;&lt;/span&gt;
&lt;a href="#what-was-simulated-and-what-wasnt-tested" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Real:&lt;/strong&gt; installation through the native dialog and the standalone window; the FCM subscription; the 201s and the service worker reading the message with the tab closed, the app minimized and the window closed; the notification on screen; the click opening the app; delivery after reopening Chrome; the 410s and the cleanup.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Simulated:&lt;/strong&gt; a fake HTTPS push service on &lt;code&gt;127.0.0.1&lt;/code&gt;, to see the raw bytes that reach the &amp;ldquo;mail carrier&amp;rdquo;: 202 encrypted bytes, without the text (and the JWT&amp;rsquo;s &lt;code&gt;aud&lt;/code&gt; became &lt;code&gt;https://127.0.0.1:8799&lt;/code&gt;, port included). The test decrypted that message with a key it generated itself, not with the service worker. And the notification the lab sent to dunst beforehand, just to check that notifications would render, is synthetic, not Web Push.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Not tested:&lt;/strong&gt; iPhone, iPad and Safari; Firefox; Android; the &lt;code&gt;focus()&lt;/code&gt; branch on an already open window; &lt;code&gt;pushsubscriptionchange&lt;/code&gt;; and push with the installed app in the foreground on a subscription FCM accepted.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 data-hextra-search-id="what-this-teaches-about-the-web"&gt;What this teaches about the web&lt;span class="hx:absolute hx:-mt-20" id="what-this-teaches-about-the-web"&gt;&lt;/span&gt;
&lt;a href="#what-this-teaches-about-the-web" class="subheading-anchor" aria-label="Permalink for this section"&gt;&lt;/a&gt;&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Separating &amp;ldquo;who sends&amp;rdquo; from &amp;ldquo;who reads&amp;rdquo; is a powerful pattern:&lt;/strong&gt; the signature proves the origin, encryption protects the content, and the middleman (Google, here) only carries it, unable to open it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;HTTP status codes tell the story:&lt;/strong&gt; 201 means &amp;ldquo;accepted&amp;rdquo;, not &amp;ldquo;seen&amp;rdquo;, even when the browser is closed; 410 is &amp;ldquo;you can delete&amp;rdquo;, but it may take a while.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A PWA is a site with two extra pieces:&lt;/strong&gt; the service worker is what makes push arrive; installation changes where the click takes you.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Platform matters:&lt;/strong&gt; the same code behaves differently in incognito, in Chrome, on the iPhone.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The code and the notebook with all the output are in &lt;a href="https://github.com/sschonss/lab-web-push-vapid" target="_blank" rel="noopener"&gt;lab-web-push-vapid&lt;/a&gt;, so you can clone it and run it yourself. For reference, &lt;a href="https://web.dev/articles/push-notifications-overview" target="_blank" rel="noopener"&gt;web.dev&lt;/a&gt; has a push overview and a &lt;a href="https://web.dev/learn/pwa/" target="_blank" rel="noopener"&gt;PWA course&lt;/a&gt;, and the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Push_API" target="_blank" rel="noopener"&gt;Push API on MDN&lt;/a&gt; details each piece. The context for why this lab exists is in &lt;a href="https://luizschons.com/posts/personal-projects-as-a-lab/"&gt;Programming is still fun&lt;/a&gt;. If you&amp;rsquo;ve shipped Web Push to production, tell me in the comments what surprised you.&lt;/p&gt;</description></item></channel></rss>