def handle_info({"newfav", newklas}, socket) do
{:noreply, push_event(socket, "newfav", %{color: newklas})}
end
def handle_info({"newtitle", newtitle}, socket) do
{:noreply, push_event(socket, "newtitle", %{title: newtitle})}
end
in app.js
window.addEventListener("phx:newtitle", (e) => {
var txt = e.detail.title
var tag = document.getElementById('title')
tag.innerHTML = txt
})
window.addEventListener("phx:newfav", (e) => {
var color = e.detail.color
var tag = document.getElementById('favicon')
tag.href = `/assets/img/favicon-${color}.ico`
})
I used this technique to update both the site title and favicon. In my 2 minutes of testing on Chrome/Linux, it dynamically updates the background tab.
you can enable chrome://flags/#quick-intensive-throttling-after-loading that way it “only” takes a minute for the timer throttling to commence… think default is 5 minutes…