@devries-cameron20 / t3code Mirror · read-only / commits / 675fb1d9a7
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 13:30 UTC

fix(web): show Browser device preferences read-only for projects (#36846)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Wout Stiens committed Nov 14, 2026 at 18:45 UTC 675fb1d9a71389a8979b47990139ec94962d0e47
5 files changed +197 -8
apps/web/src/components/settings/IntegrationsSettings.browser.test.tsx new
+146
@@ -0,0 +1,146 @@
1 +import { PrimaryConnectionTarget } from "@t3tools/client-runtime/connection";
2 +import { EnvironmentId, ProjectId, ServerConfig } from "@t3tools/contracts";
3 +import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
4 +import * as Option from "effect/Option";
5 +import * as Schema from "effect/Schema";
6 +import { expect, it, vi } from "vite-plus/test";
7 +import { page, userEvent } from "vite-plus/test/browser";
8 +
9 +import { render } from "../../../test/render";
10 +import { ensureClientSettingsHydrated, persistClientSettingsPatch } from "../../hooks/useSettings";
11 +import { buildSidebarProjectSnapshots } from "../../sidebarProjectGrouping";
12 +import type { EnvironmentPresentation } from "../../state/environments";
13 +import type { Project } from "../../types";
14 +
15 +const environmentId = EnvironmentId.make("browser-settings");
16 +const config = Schema.decodeSync(ServerConfig)({
17 + environment: {
18 + environmentId,
19 + label: "Desk",
20 + platform: { os: "linux", arch: "x64" },
21 + serverVersion: "1.0.0",
22 + orchestrationProtocolVersion: 2,
23 + capabilities: {},
24 + },
25 + auth: {
26 + policy: "loopback-browser",
27 + bootstrapMethods: ["one-time-token"],
28 + sessionMethods: ["browser-session-cookie"],
29 + sessionCookieName: "t3_session",
30 + },
31 + cwd: "/workspace/browser",
32 + keybindingsConfigPath: "/workspace/keybindings.json",
33 + keybindings: [],
34 + issues: [],
35 + providers: [],
36 + availableEditors: [],
37 + observability: {
38 + logsDirectoryPath: "/workspace/logs",
39 + localTracingEnabled: false,
40 + otlpTracesEnabled: false,
41 + otlpMetricsEnabled: false,
42 + },
43 + settings: {},
44 +});
45 +const environments: EnvironmentPresentation[] = [
46 + {
47 + environmentId,
48 + label: "Desk",
49 + displayUrl: "http://localhost:12345",
50 + relayManaged: false,
51 + entry: {
52 + target: new PrimaryConnectionTarget({
53 + environmentId,
54 + label: "Desk",
55 + httpBaseUrl: "http://localhost:12345",
56 + wsBaseUrl: "ws://localhost:12345/ws",
57 + }),
58 + profile: Option.none(),
59 + enabled: true,
60 + },
61 + connection: { phase: "connected", error: null, traceId: null },
62 + serverConfig: config,
63 + },
64 +];
65 +const projects: Project[] = [
66 + {
67 + id: ProjectId.make("browser-project"),
68 + environmentId,
69 + title: "Browser project",
70 + workspaceRoot: "/workspace/browser",
71 + repositoryIdentity: null,
72 + defaultModelSelection: null,
73 + scripts: [],
74 + createdAt: "2026-11-14T00:00:00.000Z",
75 + updatedAt: "2026-11-14T00:00:00.000Z",
76 + },
77 +];
78 +
79 +// Profiles, link target and the advanced rows only work in the desktop app.
80 +vi.mock(import("../../env"), async (original) => ({ ...(await original()), isElectron: true }));
81 +vi.mock(import("../../state/environments"), async (original) => ({
82 + ...(await original()),
83 + useEnvironments: () => ({
84 + isReady: true,
85 + networkStatus: "online" as const,
86 + environments,
87 + presentationById: new Map(),
88 + }),
89 + usePrimaryEnvironmentId: () => environmentId,
90 + usePrimaryEnvironment: () => environments[0]!,
91 + readEnvironment: () => environments[0]!,
92 +}));
93 +vi.mock(import("../../state/session"), async (original) => ({
94 + ...(await original()),
95 + useEnvironmentScope: () => true,
96 + useEnvironmentsWithScope: () => new Set([environmentId]),
97 +}));
98 +vi.mock(import("../../state/entities"), async (original) => ({
99 + ...(await original()),
100 + useProjects: () => projects,
101 + useServerConfigs: () => new Map([[environmentId, config]]),
102 +}));
103 +
104 +import { BrowserSettingsPanel } from "./IntegrationsSettings";
105 +import { SettingsScopeProvider } from "./SettingsScopeContext";
106 +
107 +const [group] = buildSidebarProjectSnapshots({
108 + projects,
109 + settings: DEFAULT_CLIENT_SETTINGS,
110 + primaryEnvironmentId: environmentId,
111 + resolveEnvironmentLabel: () => "Desk",
112 +});
113 +const isInert = (element: Element) => element.closest("[inert]") !== null;
114 +
115 +it.each([
116 + { scope: "a project", search: { project: group!.projectKey } },
117 + {
118 + scope: "a checkout",
119 + search: { project: group!.projectKey, checkout: group!.memberProjects[0]!.physicalProjectKey },
120 + },
121 +])("shows device preferences read-only for $scope", async ({ search }) => {
122 + await ensureClientSettingsHydrated();
123 + await persistClientSettingsPatch(
124 + { browserProfiles: [{ id: "work", name: "Work", kind: "persistent" }] },
125 + async () => {},
126 + );
127 + await using screen = await render(
128 + <SettingsScopeProvider search={search} onChange={() => {}}>
129 + <BrowserSettingsPanel />
130 + </SettingsScopeProvider>,
131 + { router: "/settings/browser" },
132 + );
133 +
134 + for (const name of ["Search engine", "Open links in"]) {
135 + expect(isInert(screen.getByRole("combobox", { name }).element())).toBe(true);
136 + }
137 + expect(isInert(screen.getByRole("switch", { name: "Agent browser access" }).element())).toBe(
138 + false,
139 + );
140 + // Profiles save for this device in every scope, but the default profile is a device preference.
141 + await expect.element(screen.getByRole("button", { name: "Add profile" })).toBeEnabled();
142 + await userEvent.click(screen.getByRole("button", { name: "Work options" }));
143 + await expect
144 + .element(page.getByRole("menuitem", { name: "Set as default" }))
145 + .toHaveAttribute("aria-disabled", "true");
146 +});
apps/web/src/components/settings/IntegrationsSettings.tsx
+14 -1
@@ -369,6 +369,7 @@ function BrowserViewportSetting({ disabled }: { readonly disabled: boolean }) {
369 return (
370 <SettingsRow
371 {...searchableSetting("browser-default-viewport")}
372 + devicePreference
373 description="Tab size for you and agents. Fill fits the panel; other sizes show the device toolbar."
374 resetAction={
375 !disabled && viewport._tag !== DEFAULT_BROWSER_VIEWPORT._tag ? (
@@ -477,6 +478,7 @@ function BrowserZoomSetting({ disabled }: { readonly disabled: boolean }) {
478 return (
479 <SettingsRow
480 {...searchableSetting("browser-default-zoom")}
481 + devicePreference
482 description="Page zoom applied to new browser tabs."
483 resetAction={
484 !disabled && zoomFactor !== DEFAULT_PREVIEW_ZOOM_FACTOR ? (
@@ -520,6 +522,7 @@ function BrowserAppearanceSetting({ disabled }: { readonly disabled: boolean })
522 return (
523 <SettingsRow
524 {...searchableSetting("browser-default-appearance")}
525 + devicePreference
526 description="The color scheme pages are told to prefer. System follows your OS setting."
527 resetAction={
528 !disabled && appearance !== DEFAULT_PREVIEW_APPEARANCE ? (
@@ -567,6 +570,7 @@ function BrowserRecordingInputSettings({ disabled }: { readonly disabled: boolea
570 <>
571 <SettingsRow
572 {...searchableSetting("browser-recording-key-presses")}
573 + devicePreference
574 description="Show pressed keys and shortcuts in new recordings. Password fields are excluded."
575 control={
576 <Switch
@@ -581,6 +585,7 @@ function BrowserRecordingInputSettings({ disabled }: { readonly disabled: boolea
585 />
586 <SettingsRow
587 {...searchableSetting("browser-recording-mouse-presses")}
588 + devicePreference
589 description="Highlight mouse presses and held buttons in new recordings."
590 control={
591 <Switch
@@ -604,6 +609,7 @@ function BrowserRecordingFrameRateSetting({ disabled }: { readonly disabled: boo
609 return (
610 <SettingsRow
611 {...searchableSetting("browser-recording-frame-rate")}
612 + devicePreference
613 description="Maximum recording rate. 30 fps saves CPU and storage; 60 fps is smoother."
614 resetAction={
615 !disabled && frameRate !== DEFAULT_BROWSER_RECORDING_FRAME_RATE ? (
@@ -658,6 +664,7 @@ function BrowserLinkTargetSetting({ disabled }: { readonly disabled: boolean })
664 return (
665 <SettingsRow
666 {...searchableSetting("browser-link-target")}
667 + devicePreference
668 description="Where links in the chat and terminal open. Hold ⌘ or Ctrl while clicking a link to open it in your default browser either way."
669 resetAction={
670 !disabled && linkTarget !== DEFAULT_BROWSER_LINK_TARGET ? (
@@ -712,6 +719,7 @@ function BrowserSearchEngineSetting() {
719 <>
720 <SettingsRow
721 {...searchableSetting("browser-search-engine")}
722 + devicePreference
723 description="What the address bar searches when you type something that isn't a URL."
724 resetAction={
725 engine !== DEFAULT_BROWSER_SEARCH_ENGINE || customUrl !== "" ? (
@@ -752,6 +760,7 @@ function BrowserSearchEngineSetting() {
760 {engine === "custom" ? (
761 <SettingsRow
762 title="Custom search URL"
763 + devicePreference
764 description="Use %s where the search terms go."
765 status={
766 isValidSearchUrlTemplate(customUrl)
@@ -1080,6 +1089,7 @@ function BrowserAutoShowFloatingPreviewSetting({ disabled }: { readonly disabled
1089 return (
1090 <SettingsRow
1091 {...searchableSetting("browser-auto-show-floating-preview")}
1092 + devicePreference
1093 description="Show the floating preview when an agent opens a browser or device unless the agent says otherwise."
1094 resetAction={
1095 !disabled && autoShow !== DEFAULT_BROWSER_AUTO_SHOW_FLOATING_PREVIEW ? (
@@ -1114,6 +1124,9 @@ function BrowserProfilesSetting({ disabled }: { readonly disabled: boolean }) {
1124 // Profile edits pair with profile data on disk, so they save for this device in every scope.
1125 const updateSettings = useUpdatePrimarySettings();
1126 const updateDefaultProfile = useUpdateScopedSettings();
1127 + const { scope } = useSettingsScope();
1128 + // The default profile is a device preference, which a project cannot override.
1129 + const defaultProfileReadOnly = scope.kind === "project" || scope.kind === "checkout";
1130 const { environments, isReady: environmentsReady } = useEnvironments();
1131 const primaryEnvironment = usePrimaryEnvironment();
1132 // Cookie import runs on this desktop, whose policy the primary environment reports.
@@ -1421,7 +1434,7 @@ function BrowserProfilesSetting({ disabled }: { readonly disabled: boolean }) {
1434 </MenuTrigger>
1435 <MenuPopup align="end">
1436 <MenuItem
1424 - disabled={!settingsHydrated || isDefault}
1437 + disabled={!settingsHydrated || isDefault || defaultProfileReadOnly}
1438 onClick={() => {
1439 if (settingsHydrated) {
1440 updateDefaultProfile({ browserDefaultProfileId: profile.id });
apps/web/src/components/settings/settingsLayout.tsx
+11 -3
@@ -310,6 +310,7 @@ export function SettingsRow({
310 onResetOverride,
311 control,
312 serverScoped = false,
313 + devicePreference = false,
314 settingKeys = EMPTY_SETTING_KEYS,
315 managedPaths = EMPTY_MANAGED_PATHS,
316 mixed: mixedOverride,
@@ -325,6 +326,8 @@ export function SettingsRow({
326 onResetOverride?: () => void;
327 control?: ReactNode;
328 serverScoped?: boolean;
329 + /** Saved on this device, so a project cannot override it and the row is read-only there. */
330 + devicePreference?: boolean;
331 settingKeys?: readonly (keyof ServerSettings)[];
332 /** Dot paths inside a setting, such as `storageCleanup.logsAfterDays`, an administrator can lock. */
333 managedPaths?: readonly string[];
@@ -369,6 +372,7 @@ export function SettingsRow({
372 context !== null && (context.scope.kind === "project" || context.scope.kind === "checkout");
373 const scopedKeys = settingKeys.filter(isProjectScopedSettingKey);
374 const environmentWide = isProjectScope && serverScoped && scopedKeys.length === 0;
375 + const deviceReadOnly = isProjectScope && devicePreference;
376 const mixed =
377 mixedOverride ?? (context !== null && scopedSettingsAreMixed(context.targets, settingKeys));
378 const source =
@@ -392,8 +396,10 @@ export function SettingsRow({
396 );
397 const overridingProjects = isProjectScope ? [] : projectOverrides(context, scopedKeys);
398 const renderedReset =
395 - unavailable || managedBy !== undefined || managed !== undefined ? null : isProjectScope &&
396 - scopedKeys.length > 0 ? (
399 + unavailable ||
400 + deviceReadOnly ||
401 + managedBy !== undefined ||
402 + managed !== undefined ? null : isProjectScope && scopedKeys.length > 0 ? (
403 source === "project" || source === "mixed" ? (
404 <SettingResetButton
405 label={typeof title === "string" ? title : "override"}
@@ -446,7 +452,9 @@ export function SettingsRow({
452 )
453 : environmentWide && control
454 ? inertControl("Environment-wide setting. Select an environment to change it.")
449 - : control;
455 + : deviceReadOnly && control
456 + ? inertControl("Saved on this device. Select All projects to change it.")
457 + : control;
458 const customized =
459 context !== null &&
460 settingKeys.some((key) =>
docs/user/project-settings.md
+6 -4
@@ -5,10 +5,12 @@ the project and environment a change applies to. Pages that only hold device pre
5 Appearance, don't show it. They start at **All projects** and **All environments**
6 and stay selected as you move between categories or search for a setting.
7
8 -Preferences saved on this device, such as appearance, confirmations and browser profiles, always
9 -show and ignore the selection. Everything else is stored on a server. Choose one environment to
10 -edit its settings, or leave **All environments** to edit every connected environment at once.
11 -Offline environments keep their current values; this is a bulk edit, not a synced global default.
8 +Preferences saved on this device, such as appearance, confirmations and browser profiles, ignore
9 +the environment selection. On the Browser page they are read-only while a project is selected,
10 +though profiles can still be added, renamed and removed. Everything else is stored on a server.
11 +Choose one environment to edit its settings, or leave **All environments** to edit every connected
12 +environment at once. Offline environments keep their current values; this is a bulk edit, not a
13 +synced global default.
14
15 Choose a project to override settings for it on the selected environments. A layers icon beside
16 each server row's title shows where the value comes from: the built-in default, the environment,
scripts/scenarios/browser-search-engine-read-only-in-project.e2e.ts new
+20
@@ -0,0 +1,20 @@
1 +import { expect } from "e2e";
2 +
3 +import { test, WEB } from "./t3.ts";
4 +
5 +test(
6 + "Browser's Search engine is read-only while a project is selected",
7 + WEB,
8 + async ({ t3, app, browser, screen }) => {
9 + await t3.project("demo");
10 + await t3.open("/settings/browser");
11 +
12 + await screen.getByRole("button", "Project scope: All projects").tap();
13 + await screen.getByRole("menuitemradio").filter({ hasText: "demo" }).tap();
14 + await expect(screen.getByRole("button", "Project scope: demo")).toBeVisible();
15 + await app.screenshot("project-selected");
16 +
17 + // A project cannot override a device preference, so the control must not offer an edit.
18 + await expect(browser.locator('[inert] [aria-label="Search engine"]')).toBeVisible();
19 + },
20 +);