The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Top bar: a link the service may send; the balance carries the browser's time zone
Adarsh95de594ac9e0
diff --git a/src/app/api/status/route.ts b/src/app/api/status/route.tsindex fc3cc2d5..4c69343e 100644--- a/src/app/api/status/route.ts+++ b/src/app/api/status/route.ts@@ -6,6 +6,7 @@ import { PROVIDERS } from "@/server/providers";import { comfyRam, probeComfy } from "@/server/providers/comfyui";import { llmBackends } from "@/server/providers/llm";import { nothingConnected, type EngineModeName } from "@/lib/connections";+import { zoneOf } from "@/lib/nav-link";import { getSetting, setSetting } from "@/server/settings";import { offeredSummary } from "@/server/model-access";import { poolOwnModels } from "@/server/pool-own-setup";@@ -18,7 +19,10 @@ export async function GET(request?: Request) {await connection();// A guest or an account (public sign-up) sees its own GPU, never the install's providers or servers.const viewer = request ? requestViewer(request) : ({ kind: "owner" } as const);- if (viewer.kind !== "owner") return Response.json(await visitorStatus(viewer.kind === "account" ? viewer.account : null), { headers: { "Cache-Control": "no-store" } });+ if (viewer.kind !== "owner") {+ const zone = viewer.kind === "account" ? zoneOf(request?.headers.get("cookie")) : null;+ return Response.json(await visitorStatus(viewer.kind === "account" ? viewer.account : null, zone), { headers: { "Cache-Control": "no-store" } });+ }// Both asked first, so the llm provider's label and routing read fresh answers without waiting.const [comfy, local] = await Promise.all([probeComfy(true), localSummary()]);const ram = comfy ? comfyRam() : undefined;diff --git a/src/components/nav/phone-sheets.tsx b/src/components/nav/phone-sheets.tsxindex 4563efaa..4e80feff 100644--- a/src/components/nav/phone-sheets.tsx+++ b/src/components/nav/phone-sheets.tsx@@ -9,7 +9,7 @@ import { AccountSections } from "@/components/nav/account-menu";import { CreateList } from "@/components/nav/create-menu";import { PHONE_QUERY, useNavUi, type NavSheet } from "@/components/nav/nav-ui";import { useSearchPalette } from "@/components/nav/search-context";-import { ComputerNoteBlock } from "@/components/nav/status-chips";+import { ComputerNoteBlock, NavLinkBlock } from "@/components/nav/status-chips";import { FamilySwitch, StudiosSheet } from "@/components/nav/studios-sheet";import { MEGA_AREAS, type MegaId } from "@/lib/mega-menus";import { warmNav } from "@/components/nav/nav-prefetch";@@ -63,6 +63,7 @@ export function sheetReturnTarget(opener: HTMLElement | null, shown: NavSheet, tfunction YouSheet() {return (<div className="flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto overscroll-contain px-4 pb-1 [--nav-icon:18px]">+ <NavLinkBlock /><ComputerNoteBlock /><AccountSections variant="sheet" /></div>diff --git a/src/components/nav/status-chips.tsx b/src/components/nav/status-chips.tsxindex c78895b2..a79bc94e 100644--- a/src/components/nav/status-chips.tsx+++ b/src/components/nav/status-chips.tsx@@ -2,7 +2,7 @@import dynamic from "next/dynamic";import { cloneElement } from "react";-import { ChevronDown, Cpu, KeyRound, Server } from "lucide-react";+import { ChevronDown, Cpu, KeyRound, Server, Sparkles } from "lucide-react";import { PlaceholdersOnChip } from "@/components/demo-mode";import { IntentLink } from "@/components/intent-link";import { awayFix, openConnect, useComputerSupport } from "@/components/gpu/open-connect";@@ -17,6 +17,7 @@ import { placeholdersOn } from "@/lib/demo-mode";import { deviceLabel } from "@/lib/gpu/readiness";import { shortState } from "@/lib/diagnose";import { safeLink, useInterest, type BalanceRow } from "@/lib/hosted";+import type { NavLink } from "@/lib/nav-link";import type { ViewerKind } from "@/lib/nav-model";import { barRuns, type BarRuns, type RunOnPick } from "@/lib/run-place";import { useSetRunOn } from "@/lib/run-on";@@ -465,18 +466,20 @@ export function avatarDot(kind: ViewerKind | undefined, status: StatusInfo | und* pre-paint script keeps their room on the next load (html[data-had-balance|computer|placeholders]). Mounted once, in* the bar. Nothing is remembered until the viewer and the status are known.*/-export function useRememberPills(kind: ViewerKind | undefined): { balance: boolean; computer: boolean; placeholders: boolean } {+export function useRememberPills(kind: ViewerKind | undefined): { balance: boolean; computer: boolean; placeholders: boolean; navlink: boolean } {const status = useShownStatus();const viewer = useViewer().data;const hydrated = useHydrated();const known = !!kind && !!status;const balance = known && !!status.viewer?.balance;+ const navlink = known && !!status.viewer?.navLink;+ useHadItems("navlink", known ? Number(navlink) : undefined);const computer = hydrated && !!kind && viewer?.computer === true;const placeholders = usePlaceholdersOn(kind);useHadItems("balance", known ? Number(balance) : undefined);useHadItems("computer", hydrated && kind ? Number(computer) : undefined);useHadItems("placeholders", known ? Number(placeholders) : undefined);- return { balance, computer, placeholders };+ return { balance, computer, placeholders, navlink };}/**@@ -519,11 +522,21 @@ export function ComputerNoteBlock() {* time takes no room, one that had a pill keeps it until the status says otherwise.*/export function BarPills({ kind }: { kind: ViewerKind | undefined }) {- const { balance, computer, placeholders } = useRememberPills(kind);+ const { balance, computer, placeholders, navlink } = useRememberPills(kind);const status = useShownStatus();const known = !!kind && !!status;return (<>+ {known ? (+ navlink &&+ status.viewer?.navLink && (+ <span data-slot="navlink-pill" className={cn("flex shrink-0", PILL_W.navlink)}>+ <NavLinkPill link={status.viewer.navLink} className="w-full" />+ </span>+ )+ ) : (+ <span aria-hidden data-slot="navlink-pill" className={cn("hidden shrink-0 [html[data-had-navlink]_&]:block", PILL_W.navlink)} />+ )}{known ? (balance &&status.viewer && (@@ -557,4 +570,31 @@ export function BarPills({ kind }: { kind: ViewerKind | undefined }) {}/** Each pill's fixed width: the kept room before the status is known is exactly what the pill takes after. */-export const PILL_W = { balance: "w-40 xl:w-[184px]", computer: "w-9 xl:w-[140px]", placeholders: "w-[136px]" } as const;+export const PILL_W = { balance: "w-40 xl:w-[184px]", computer: "w-9 xl:w-[140px]", placeholders: "w-[136px]", navlink: "w-9 min-[1440px]:w-[132px]" } as const;++/**+ * The billing service's link for the bar (viewer.navLink, src/lib/nav-link.ts): a filled pill, its words from 1440 px+ * and an icon with its name for screen readers below. `wide`: the words always (the phone's You sheet).+ */+export function NavLinkPill({ link, wide, className }: { link: NavLink; wide?: boolean; className?: string }) {+ return (+ <IntentLink+ href={link.url}+ title={link.label}+ className={cn(+ "nav-focus-out inline-flex h-9 shrink-0 items-center justify-center gap-1.5 rounded-full bg-primary px-2 text-[13px] font-semibold whitespace-nowrap text-primary-foreground nav-hover:bg-primary/90 active:bg-primary/85 motion-safe:transition-colors [@media(pointer:coarse)]:h-11",+ wide ? "w-full px-4" : "min-[1440px]:px-3.5",+ className,+ )}+ >+ <Sparkles aria-hidden className="size-4 shrink-0" />+ <span className={cn("truncate", !wide && "sr-only min-[1440px]:not-sr-only")}>{link.label}</span>+ </IntentLink>+ );+}++/** The service's link first in the phone's You sheet, when it sent one. */+export function NavLinkBlock() {+ const link = useShownStatus()?.viewer?.navLink;+ return link ? <NavLinkPill link={link} wide /> : null;+}diff --git a/src/lib/api.ts b/src/lib/api.tsindex 8ed7714e..854cdb95 100644--- a/src/lib/api.ts+++ b/src/lib/api.ts@@ -1066,6 +1066,8 @@ export interface StatusInfo {cardText?: string;/** The billing service's words for open models in the model menu, by id, in place of "Free" (src/lib/model-marks.ts). */marks?: Record<string, string>;+ /** The billing service's link for the top bar (src/lib/nav-link.ts): its words and a same-site address. */+ navLink?: { label: string; url: string };/** What this studio's GPUs keep off, for a viewer with no GPU of its own: its pickers leave it out (src/lib/pool-rules.ts). */pool?: PoolRules;/** The billing service's words for the account's balance (src/server/billing.ts). */diff --git a/src/lib/nav-link.ts b/src/lib/nav-link.tsnew file mode 100644index 00000000..71e2a1f0--- /dev/null+++ b/src/lib/nav-link.ts@@ -0,0 +1,48 @@+/**+ * A link the billing service may ask the top bar to show (Policy.navLink, src/server/billing.ts): its words and a+ * same-site address. The bar shows it beside the balance from md up, and the phone's You sheet first.+ */+export interface NavLink {+ label: string;+ url: string;+}++/** The longest words the bar shows on the link. */+export const NAV_LINK_MAX = 24;++/** The words and address as the bar shows them, or null when either is missing, too long or not a same-site path. */+export function cleanNavLink(raw: unknown): NavLink | null {+ if (!raw || typeof raw !== "object") return null;+ const { label, url } = raw as { label?: unknown; url?: unknown };+ if (typeof label !== "string" || typeof url !== "string") return null;+ const words = label.replace(/[\u0000-\u001f\u007f]/g, "").replace(/\s+/g, " ").trim();+ if (!words || words.length > NAV_LINK_MAX) return null;+ if (!url.startsWith("/") || url.startsWith("//") || url.includes("\\") || url.length > 300) return null;+ return { label: words, url };+}++/**+ * The browser's own time zone, an IANA name such as "Asia/Kolkata" or "America/Argentina/Buenos_Aires" (the fuobe_tz+ * cookie, set before the first paint: src/lib/nav.ts), or null when it isn't one.+ */+export function cleanZone(raw: string | null | undefined): string | null {+ if (!raw || raw.length > 64) return null;+ return /^[A-Za-z][A-Za-z0-9_+-]*(\/[A-Za-z0-9_+-]+){0,2}$/.test(raw) ? raw : null;+}++/** The cookie the browser's time zone travels in. */+export const ZONE_COOKIE = "fuobe_tz";++/** The browser's time zone from a request's Cookie header, or null when it has none or not a zone name. */+export function zoneOf(cookieHeader: string | null | undefined): string | null {+ for (const part of (cookieHeader ?? "").split(";")) {+ const at = part.indexOf("=");+ if (at < 0 || part.slice(0, at).trim() !== ZONE_COOKIE) continue;+ try {+ return cleanZone(decodeURIComponent(part.slice(at + 1).trim()));+ } catch {+ return null;+ }+ }+ return null;+}diff --git a/src/lib/nav.ts b/src/lib/nav.tsindex 7fecbae4..44b7362e 100644--- a/src/lib/nav.ts+++ b/src/lib/nav.ts@@ -1,5 +1,7 @@/** App frame helpers (pure, so they're testable): which link is the open page, full-screen studios, the pre-paint script. */+import { ZONE_COOKIE } from "./nav-link";+export const groupId = (label: string) => label.toLowerCase().replace(/[^a-z0-9]+/g, "-");/** "New creation" (the top bar, the phone's Create sheet): Home with a fresh composer, so it does more than the Home row. Home drops the flag. */@@ -49,13 +51,15 @@ export function fullScreenStudio(pathname: string): string | null {}/** The bar's pills whose room is kept from the first paint (use-had-items.ts names, remembered by the bar). */-export const CHROME_HAD_PILLS = ["balance", "computer", "placeholders"] as const;+export const CHROME_HAD_PILLS = ["balance", "computer", "placeholders", "navlink"] as const;/*** Inline script that runs while the HTML is parsed, so the app frame has its final shape on the first paint (the* server renders one shell for everyone): `data-fullscreen-studio` on a full-screen studio (the phone's tab bar* gives it the whole screen), `data-viewer` as this browser last knew it ("fuobe:viewer", as api.ts's VIEWER_KEY:* the bar's right side keeps a guest's or an account's room), and `data-had-<pill>` for the bar's pills it showed- * last (use-had-items.ts). Every read is guarded: blocked storage leaves the defaults.+ * last (use-had-items.ts). It also keeps the browser's time zone in the fuobe_tz cookie, so the billing service says+ * when a limit resets in the reader's own time (src/lib/nav-link.ts). Every read is guarded: blocked storage leaves the+ * defaults.*/-export const CHROME_STATE_SCRIPT = `(function(){var d=document.documentElement;try{if(${FULL_SCREEN}.test(location.pathname))d.setAttribute("data-fullscreen-studio","")}catch(e){}try{var v=localStorage.getItem("fuobe:viewer");if(v==="guest"||v==="account"||v==="owner")d.setAttribute("data-viewer",v)}catch(e){}try{${JSON.stringify(CHROME_HAD_PILLS)}.forEach(function(n){var x=localStorage.getItem("fuobe:had:"+n);if(x&&/^[1-9][0-9]?$/.test(x))d.setAttribute("data-had-"+n,x)})}catch(e){}})()`;+export const CHROME_STATE_SCRIPT = `(function(){var d=document.documentElement;try{if(${FULL_SCREEN}.test(location.pathname))d.setAttribute("data-fullscreen-studio","")}catch(e){}try{var v=localStorage.getItem("fuobe:viewer");if(v==="guest"||v==="account"||v==="owner")d.setAttribute("data-viewer",v)}catch(e){}try{${JSON.stringify(CHROME_HAD_PILLS)}.forEach(function(n){var x=localStorage.getItem("fuobe:had:"+n);if(x&&/^[1-9][0-9]?$/.test(x))d.setAttribute("data-had-"+n,x)})}catch(e){}try{var z=Intl.DateTimeFormat().resolvedOptions().timeZone,c="${ZONE_COOKIE}="+encodeURIComponent(z||"");if(z&&(";"+document.cookie.replace(/ /g,"")+";").indexOf(";"+c+";")<0)document.cookie=c+";path=/;max-age=31536000;samesite=lax"+(location.protocol==="https:"?";secure":"")}catch(e){}})()`;diff --git a/src/server/account-gpu.ts b/src/server/account-gpu.tsindex a4e3e6fe..bfce4a20 100644--- a/src/server/account-gpu.ts+++ b/src/server/account-gpu.ts@@ -3,6 +3,7 @@ import dns from "node:dns/promises";import net from "node:net";import { cleanCopy, type ServiceCopy } from "@/lib/service-copy";import { cleanMarks, type ModelMarks } from "@/lib/model-marks";+import { cleanNavLink, type NavLink } from "@/lib/nav-link";import { isCloudProvider, type CloudProvider } from "@/lib/your-keys";import { accountEngineMode, accountKeyInfo, accountProviders, paidAllowed, usableProviders } from "./account-keys";import { accountGpu, type Account, type AccountGpu } from "./auth";@@ -378,6 +379,8 @@ export interface VisitorView {* Only while the viewer's runs go to this install's GPUs.*/marks?: ModelMarks;+ /** The billing service's link for the top bar (src/lib/nav-link.ts): its words and a same-site address. */+ navLink?: NavLink;/*** What this install's GPUs keep off (the policy's model and app lists, and its kinds), for a visitor with no GPU of its* own: its pickers leave those out instead of failing at Run. Absent: nothing is kept off, or it has a GPU of its own.@@ -441,9 +444,10 @@ export type VisitorTrouble = Pick<Diagnosis, "cause" | "words" | "actions" | "re* GET /api/status for a guest or an account: ComfyUI is its own GPU (taken as there until it has one,* so the studios offer Generate and the run asks it to connect one), fal.ai and Replicate are its own* keys, the engine mode they allow (account-keys.ts), no Demo mode, and nothing of the install's own- * servers, keys or addresses.+ * servers, keys or addresses. `zone`: the browser's own time zone (the fuobe_tz cookie, src/lib/nav-link.ts), passed+ * on to the billing service with the balance.*/-export async function visitorStatus(account: Account | null) {+export async function visitorStatus(account: Account | null, zone?: string | null) {const gpu = account ? accountGpu(account.id) : null;const live = account && gpu ? await gpuState(account.id, gpu) : null;const keys = account ? accountProviders(account.id) : [];@@ -501,10 +505,13 @@ export async function visitorStatus(account: Account | null) {const toSite = !gpu || viewer.runOn === "site" || (!viewer.runOn && p?.prefer === "pool");const marks = p?.hosted && toSite ? cleanMarks(p.marks) : null;if (marks) viewer.marks = marks;+ // The service's link for the top bar, for guests and accounts alike.+ const navLink = p?.hosted ? cleanNavLink(p.navLink) : null;+ if (navLink) viewer.navLink = navLink;// The service's display copy (wait and limit lines), for guests and accounts alike.const copy = p?.hosted ? cleanCopy(p.copy) : null;if (copy) viewer.copy = copy;- const b = account ? await billingBalance(account.id) : null;+ const b = account ? await billingBalance(account.id, zone) : null;if (b) viewer.balance = b;}const configured = (id: string) => (id === "comfyui" ? (gpu ? !!live?.online : true) : isCloudProvider(id) && keys.includes(id));diff --git a/src/server/billing.ts b/src/server/billing.tsindex 4f58e477..c09ae800 100644--- a/src/server/billing.ts+++ b/src/server/billing.ts@@ -227,6 +227,11 @@ export interface Policy {* go to this install's GPUs (src/lib/model-marks.ts; at most MARK_MAX characters each). Absent: "Free" as before.*/marks?: Record<string, string>;+ /**+ * A link the top bar shows beside the balance (and the phone's You sheet first), for guests and accounts alike: short+ * words and a same-site address (src/lib/nav-link.ts). Absent: no link there.+ */+ navLink?: { label: string; url: string };ttlS: number;}@@ -691,14 +696,18 @@ export function refusalStatus(code: RefuseCode | "price-changed"): number {export const BILLING_HEADER = "x-fuobe-billing";-/** The account's balance (cached 10 s). No service, or no answer: null (nothing to show). */-export async function balance(accountId: string): Promise<Balance | null> {+/**+ * The account's balance (cached 10 s). No service, or no answer: null (nothing to show). `zone`: the browser's own time+ * zone (src/lib/nav-link.ts cleanZone), so the service's words give a reset's time in the reader's own clock.+ */+export async function balance(accountId: string, zone?: string | null): Promise<Balance | null> {if (!billingConfigured()) return null;const cache = (globalThis.__fuobeBillingBalances ??= new Map());const hit = cache.get(accountId);if (hit && Date.now() - hit.at < 10_000) return hit.balance;try {- const b = await call<Balance>("GET", `/v1/balance?account=${encodeURIComponent(accountId)}`, undefined, BILLING_TIMEOUTS.balance);+ const tz = zone ? `&tz=${encodeURIComponent(zone)}` : "";+ const b = await call<Balance>("GET", `/v1/balance?account=${encodeURIComponent(accountId)}${tz}`, undefined, BILLING_TIMEOUTS.balance);cache.set(accountId, { at: Date.now(), balance: b });if (cache.size > 5000) cache.delete(cache.keys().next().value!);return b;diff --git a/tests/auto-image-pool.test.ts b/tests/auto-image-pool.test.tsindex fd380744..130a25ac 100644--- a/tests/auto-image-pool.test.ts+++ b/tests/auto-image-pool.test.ts@@ -345,4 +345,16 @@ describe("an account's own Auto order and menu words from the billing service",billing.resetBillingCache();expect((await visitorStatus(acct)).viewer?.marks).toBeUndefined();});++ it("the bar's link reaches guests and accounts cleaned, and the balance carries the browser's time zone", async () => {+ fake.policy = { ...FAKE_POLICY, navLink: { label: "Go Unlimited", url: "/pricing?from=nav" } } as typeof FAKE_POLICY;+ const acct = auth.createAccount(`navlink-${++n}@example.com`, "long enough");+ const { visitorStatus } = await import("@/server/account-gpu");+ expect((await visitorStatus(acct, "Asia/Kolkata")).viewer?.navLink).toEqual({ label: "Go Unlimited", url: "/pricing?from=nav" });+ expect((await visitorStatus(null)).viewer?.navLink).toEqual({ label: "Go Unlimited", url: "/pricing?from=nav" });+ expect(fake.calls_of("/v1/balance").at(-1)?.path).toBe(`/v1/balance?account=${encodeURIComponent(acct.id)}&tz=Asia%2FKolkata`);+ fake.policy = { ...FAKE_POLICY, navLink: { label: "Go", url: "https://example.com" } } as typeof FAKE_POLICY;+ billing.resetBillingCache();+ expect((await visitorStatus(acct)).viewer?.navLink).toBeUndefined();+ });});diff --git a/tests/nav-link.test.ts b/tests/nav-link.test.tsnew file mode 100644index 00000000..ffa748b1--- /dev/null+++ b/tests/nav-link.test.ts@@ -0,0 +1,31 @@+import { describe, expect, it } from "vitest";+import { cleanNavLink, cleanZone, NAV_LINK_MAX, zoneOf } from "@/lib/nav-link";++describe("the service's link for the bar", () => {+ it("keeps short words and a same-site path", () => {+ expect(cleanNavLink({ label: " Go\n Unlimited ", url: "/pricing?from=nav" })).toEqual({ label: "Go Unlimited", url: "/pricing?from=nav" });+ });++ it("drops anything else", () => {+ for (const bad of [null, "x", { label: "Go" }, { url: "/p" }, { label: "", url: "/p" }, { label: "x".repeat(NAV_LINK_MAX + 1), url: "/p" },+ { label: "Go", url: "https://example.com/p" }, { label: "Go", url: "//example.com" }, { label: "Go", url: "/\\example.com" }, { label: 3, url: "/p" }]) {+ expect(cleanNavLink(bad), JSON.stringify(bad)).toBeNull();+ }+ });+});++describe("the browser's time zone", () => {+ it("takes IANA names only", () => {+ for (const z of ["Asia/Kolkata", "America/Argentina/Buenos_Aires", "UTC", "Etc/GMT+5", "America/Port-au-Prince"]) expect(cleanZone(z), z).toBe(z);+ for (const z of [null, "", "../etc", "Asia/Kolkata;x", "A/B/C/D", "<script>", "x".repeat(65), "/Asia"]) expect(cleanZone(z), String(z)).toBeNull();+ });++ it("reads it from a Cookie header", () => {+ expect(zoneOf("a=1; fuobe_tz=Asia%2FKolkata; b=2")).toBe("Asia/Kolkata");+ expect(zoneOf("fuobe_tz=Europe/London")).toBe("Europe/London");+ expect(zoneOf("fuobe_tz=%E0%A4")).toBeNull();+ expect(zoneOf("fuobe_tz=..%2Fx")).toBeNull();+ expect(zoneOf("xfuobe_tz=Asia%2FKolkata")).toBeNull();+ expect(zoneOf(null)).toBeNull();+ });+});diff --git a/tests/nav.test.ts b/tests/nav.test.tsindex 833acadf..e6c1a917 100644--- a/tests/nav.test.ts+++ b/tests/nav.test.ts@@ -114,7 +114,7 @@ describe("the app frame's state before the first paint", () => {expect(attrs.get("data-had-balance")).toBe("1");expect(attrs.has("data-had-computer")).toBe(false);expect(attrs.has("data-had-placeholders")).toBe(false);- expect([...CHROME_HAD_PILLS]).toEqual(["balance", "computer", "placeholders"]);+ expect([...CHROME_HAD_PILLS]).toEqual(["balance", "computer", "placeholders", "navlink"]);// Anything but a known kind is ignored.expect(run("/", { "fuobe:viewer": "admin" }).has("data-viewer")).toBe(false);});@@ -125,4 +125,21 @@ describe("the app frame's state before the first paint", () => {expect(attrs.has("data-fullscreen-studio")).toBe(true);expect(attrs.has("data-viewer")).toBe(false);});++ /** The script with a cookie jar, a time zone and a protocol: what it leaves in document.cookie. */+ function cookieRun(zone: string | undefined, cookie = "", protocol = "https:") {+ const doc = { documentElement: { setAttribute: () => {} }, cookie };+ const Intl = { DateTimeFormat: () => ({ resolvedOptions: () => ({ timeZone: zone }) }) };+ new Function("document", "localStorage", "location", "Intl", CHROME_STATE_SCRIPT)(doc, { getItem: () => null }, { pathname: "/", protocol }, Intl);+ return doc.cookie;+ }++ it("keeps the browser's time zone in a cookie, only when it changed", () => {+ expect(cookieRun("Asia/Kolkata")).toBe("fuobe_tz=Asia%2FKolkata;path=/;max-age=31536000;samesite=lax;secure");+ expect(cookieRun("Asia/Kolkata", "", "http:")).toBe("fuobe_tz=Asia%2FKolkata;path=/;max-age=31536000;samesite=lax");+ // Already there: the jar is left alone (a real jar would only hold name=value).+ expect(cookieRun("Asia/Kolkata", "a=1; fuobe_tz=Asia%2FKolkata")).toBe("a=1; fuobe_tz=Asia%2FKolkata");+ expect(cookieRun("Europe/London", "fuobe_tz=Asia%2FKolkata")).toContain("fuobe_tz=Europe%2FLondon;");+ expect(cookieRun(undefined, "")).toBe("");+ });});