The best way to control Claude Code, Codex and more from any computer or phone
feat(web): choose the in-app browser's search engine (#17688)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com>
Ben Davis committed
Oct 18, 2026 at 23:03 UTC
1451e7cb23034d29774338608368a15d8845df36
9 files changed
+238
-4
apps/web/src/components/preview/PreviewView.tsx
+3
-1
@@ -22,6 +22,7 @@ import {
22
normalizePreviewUrl,
23
resolveAddressBarInput,
24
previewPdfAssetUrl,
25
+ resolveSearchUrlTemplate,
26
} from "@t3tools/shared/preview";
27
import { useEffect, useEffectEvent, useRef, useState } from "react";
28
@@ -35,6 +36,7 @@ import {
36
import { type ComposerImageAttachment, useComposerDraftStore } from "~/composerDraftStore";
37
import { capturePreviewAnnotationScreenshot } from "~/lib/previewAnnotation";
38
import { ensureLocalApi } from "~/localApi";
39
+import { getClientSettings } from "~/hooks/useSettings";
40
import {
41
rememberPreviewUrl,
42
updatePreviewServerSnapshot,
@@ -283,7 +285,7 @@ export function PreviewView({
285
286
const handleSubmitUrl = async (next: string) => {
287
try {
286
- const resolved = resolveAddressBarInput(next);
288
+ const resolved = resolveAddressBarInput(next, resolveSearchUrlTemplate(getClientSettings()));
289
if (await navigateToResolvedUrl(resolved)) {
290
recordVisitForThread(threadRef, resolved);
291
}
apps/web/src/components/settings/IntegrationsSettings.tsx
+91
@@ -9,6 +9,8 @@ import {
9
BROWSER_PROFILE_MAX_COUNT,
10
type BrowserLinkTarget,
11
type BrowserProfile,
12
+ BrowserSearchEngine,
13
+ BROWSER_CUSTOM_SEARCH_URL_MAX_LENGTH,
14
type EnvironmentId,
15
BROWSER_PROFILE_NAME_MAX_LENGTH,
16
BROWSER_RECORDING_FRAME_RATES,
@@ -16,6 +18,7 @@ import {
18
DEFAULT_BROWSER_PROFILE_ID,
19
DEFAULT_BROWSER_LINK_TARGET,
20
DEFAULT_BROWSER_RECORDING_FRAME_RATE,
21
+ DEFAULT_BROWSER_SEARCH_ENGINE,
22
DEFAULT_BROWSER_VIEWPORT,
23
DEFAULT_PREVIEW_APPEARANCE,
24
DEFAULT_PREVIEW_ZOOM_FACTOR,
@@ -32,6 +35,7 @@ import {
35
type PreviewAppearancePreference,
36
type PreviewViewportSetting,
37
} from "@t3tools/contracts";
38
+import { isValidSearchUrlTemplate } from "@t3tools/shared/preview";
39
import { PREVIEW_VIEWPORT_PRESETS } from "@t3tools/shared/previewViewport";
40
import { MoreVertical, Plus as PlusIcon } from "lucide-react";
41
import { useRef, useState } from "react";
@@ -682,6 +686,91 @@ function BrowserLinkTargetSetting({ disabled }: { readonly disabled: boolean })
686
);
687
}
688
689
+const SEARCH_ENGINE_LABELS: Readonly<Record<BrowserSearchEngine, string>> = {
690
+ duckduckgo: "DuckDuckGo",
691
+ google: "Google",
692
+ bing: "Bing",
693
+ brave: "Brave Search",
694
+ kagi: "Kagi",
695
+ ecosia: "Ecosia",
696
+ custom: "Custom",
697
+};
698
+
699
+function BrowserSearchEngineSetting() {
700
+ const engine = useClientSettings((settings) => settings.browserSearchEngine);
701
+ const customUrl = useClientSettings((settings) => settings.browserCustomSearchUrl);
702
+ const updateSettings = useUpdatePrimarySettings();
703
+
704
+ return (
705
+ <>
706
+ <SettingsRow
707
+ {...searchableSetting("browser-search-engine")}
708
+ description="What the address bar searches when you type something that isn't a URL."
709
+ resetAction={
710
+ engine !== DEFAULT_BROWSER_SEARCH_ENGINE || customUrl !== "" ? (
711
+ <SettingResetButton
712
+ label="search engine"
713
+ onClick={() =>
714
+ updateSettings({
715
+ browserSearchEngine: DEFAULT_BROWSER_SEARCH_ENGINE,
716
+ browserCustomSearchUrl: "",
717
+ })
718
+ }
719
+ />
720
+ ) : null
721
+ }
722
+ control={
723
+ <Select
724
+ value={engine}
725
+ onValueChange={(value) => {
726
+ const next = BrowserSearchEngine.literals.find((literal) => literal === value);
727
+ if (next !== undefined) {
728
+ updateSettings({ browserSearchEngine: next });
729
+ }
730
+ }}
731
+ >
732
+ <SelectTrigger size="sm" className="w-full sm:w-40" aria-label="Search engine">
733
+ <SelectValue>{SEARCH_ENGINE_LABELS[engine]}</SelectValue>
734
+ </SelectTrigger>
735
+ <SelectPopup align="end" alignItemWithTrigger={false}>
736
+ {BrowserSearchEngine.literals.map((literal) => (
737
+ <SelectItem hideIndicator key={literal} value={literal}>
738
+ {SEARCH_ENGINE_LABELS[literal]}
739
+ </SelectItem>
740
+ ))}
741
+ </SelectPopup>
742
+ </Select>
743
+ }
744
+ />
745
+ {engine === "custom" ? (
746
+ <SettingsRow
747
+ title="Custom search URL"
748
+ description="Use %s where the search terms go."
749
+ status={
750
+ isValidSearchUrlTemplate(customUrl)
751
+ ? undefined
752
+ : "Enter an http or https URL containing %s. Searches use DuckDuckGo until then."
753
+ }
754
+ control={
755
+ <DraftInput
756
+ nativeInput
757
+ size="sm"
758
+ className="w-full sm:w-64"
759
+ aria-label="Custom search URL"
760
+ placeholder="https://example.com/search?q=%s"
761
+ autoCapitalize="none"
762
+ spellCheck={false}
763
+ maxLength={BROWSER_CUSTOM_SEARCH_URL_MAX_LENGTH}
764
+ value={customUrl}
765
+ onCommit={(next) => updateSettings({ browserCustomSearchUrl: next.trim() })}
766
+ />
767
+ }
768
+ />
769
+ ) : null}
770
+ </>
771
+ );
772
+}
773
+
774
function PullRequestLinksOpenInAppSetting() {
775
const openInApp = useClientSettings((settings) => settings.pullRequestLinksOpenInApp);
776
const updateSettings = useUpdatePrimarySettings();
@@ -1534,6 +1623,8 @@ export function IntegrationsSettingsPanel() {
1623
) : (
1624
previewDefaults
1625
)}
1626
+ {/* Not desktop-only: web clients search from server-run browser tabs too. */}
1627
+ <BrowserSearchEngineSetting />
1628
<PullRequestLinksOpenInAppSetting />
1629
</SettingsSection>
1630
<DeviceIntegrationSettings />
apps/web/src/components/settings/SettingsPanels.logic.test.ts
+9
@@ -228,6 +228,15 @@ describe("getChangedBrowserSettingLabels", () => {
228
).toEqual([]);
229
});
230
231
+ it("counts a retained custom search URL so restore clears it", () => {
232
+ expect(
233
+ getChangedBrowserSettingLabels({
234
+ ...DEFAULT_UNIFIED_SETTINGS,
235
+ browserCustomSearchUrl: "https://search.example/?q=%s",
236
+ }),
237
+ ).toEqual(["Search engine"]);
238
+ });
239
+
240
it("labels each browser default that differs", () => {
241
expect(
242
getChangedBrowserSettingLabels({
apps/web/src/components/settings/SettingsPanels.logic.ts
+6
@@ -114,6 +114,8 @@ export type BrowserDefaultSettings = Pick<
114
| "browserRecordingShowKeyPresses"
115
| "browserRecordingShowMousePresses"
116
| "browserLinkTarget"
117
+ | "browserSearchEngine"
118
+ | "browserCustomSearchUrl"
119
| "browserAutoShowFloatingPreview"
120
| "pullRequestLinksOpenInApp"
121
>;
@@ -152,6 +154,10 @@ export function getChangedBrowserSettingLabels(settings: BrowserDefaultSettings)
154
...(settings.browserLinkTarget !== DEFAULT_UNIFIED_SETTINGS.browserLinkTarget
155
? ["Open links in"]
156
: []),
157
+ ...(settings.browserSearchEngine !== DEFAULT_UNIFIED_SETTINGS.browserSearchEngine ||
158
+ settings.browserCustomSearchUrl !== DEFAULT_UNIFIED_SETTINGS.browserCustomSearchUrl
159
+ ? ["Search engine"]
160
+ : []),
161
...(settings.browserAutoShowFloatingPreview !==
162
DEFAULT_UNIFIED_SETTINGS.browserAutoShowFloatingPreview
163
? ["Floating preview"]
apps/web/src/components/settings/SettingsPanels.tsx
+2
@@ -773,6 +773,8 @@ export function useSettingsRestore(onRestored?: () => void) {
773
browserRecordingShowKeyPresses: DEFAULT_UNIFIED_SETTINGS.browserRecordingShowKeyPresses,
774
browserRecordingShowMousePresses: DEFAULT_UNIFIED_SETTINGS.browserRecordingShowMousePresses,
775
browserLinkTarget: DEFAULT_UNIFIED_SETTINGS.browserLinkTarget,
776
+ browserSearchEngine: DEFAULT_UNIFIED_SETTINGS.browserSearchEngine,
777
+ browserCustomSearchUrl: DEFAULT_UNIFIED_SETTINGS.browserCustomSearchUrl,
778
browserAutoShowFloatingPreview: DEFAULT_UNIFIED_SETTINGS.browserAutoShowFloatingPreview,
779
pullRequestLinksOpenInApp: DEFAULT_UNIFIED_SETTINGS.pullRequestLinksOpenInApp,
780
enableAgentBrowserAccess: DEFAULT_UNIFIED_SETTINGS.enableAgentBrowserAccess,
apps/web/src/components/settings/settingsSearch.ts
+6
@@ -745,6 +745,12 @@ export const SETTINGS_SEARCH_ITEMS = [
745
to: "/settings/integrations",
746
searchTerms: ["links default browser in-app browser external open"],
747
},
748
+ {
749
+ id: "browser-search-engine",
750
+ title: "Search engine",
751
+ to: "/settings/integrations",
752
+ searchTerms: ["address bar duckduckgo google bing brave kagi ecosia custom"],
753
+ },
754
{
755
id: "pull-request-links-open-in-app",
756
title: "Open pull requests in T3 Code",
packages/contracts/src/settings.ts
+30
@@ -263,6 +263,25 @@ export const DEFAULT_BROWSER_RECORDING_FRAME_RATE: BrowserRecordingFrameRate = 3
263
export const BrowserLinkTarget = Schema.Literals(["system", "app"]);
264
export type BrowserLinkTarget = typeof BrowserLinkTarget.Type;
265
export const DEFAULT_BROWSER_LINK_TARGET: BrowserLinkTarget = "system";
266
+/**
267
+ * What the address bar searches with when the input is not an address.
268
+ * "custom" uses `browserCustomSearchUrl`, a template with `%s` for the query.
269
+ */
270
+export const BrowserSearchEngine = Schema.Literals([
271
+ "duckduckgo",
272
+ "google",
273
+ "bing",
274
+ "brave",
275
+ "kagi",
276
+ "ecosia",
277
+ "custom",
278
+]);
279
+export type BrowserSearchEngine = typeof BrowserSearchEngine.Type;
280
+export const DEFAULT_BROWSER_SEARCH_ENGINE: BrowserSearchEngine = "duckduckgo";
281
+export const BROWSER_CUSTOM_SEARCH_URL_MAX_LENGTH = 2048;
282
+export const BrowserCustomSearchUrl = Schema.String.check(
283
+ Schema.isMaxLength(BROWSER_CUSTOM_SEARCH_URL_MAX_LENGTH),
284
+);
285
286
export const LoadBalancingWeights = Schema.Record(
287
TrimmedNonEmptyString,
@@ -333,6 +352,15 @@ export const ClientSettingsSchema = Schema.Struct({
352
Schema.withDecodingDefault(Effect.succeed(DEFAULT_BROWSER_LINK_TARGET)),
353
),
354
355
+ browserSearchEngine: BrowserSearchEngine.pipe(
356
+ Schema.withDecodingDefault(Effect.succeed(DEFAULT_BROWSER_SEARCH_ENGINE)),
357
+ ),
358
+
359
+ // Kept when the engine is switched away from "custom" so switching back restores it.
360
+ browserCustomSearchUrl: BrowserCustomSearchUrl.pipe(
361
+ Schema.withDecodingDefault(Effect.succeed("")),
362
+ ),
363
+
364
browserAutoShowFloatingPreview: Schema.Boolean.pipe(
365
Schema.withDecodingDefault(Effect.succeed(DEFAULT_BROWSER_AUTO_SHOW_FLOATING_PREVIEW)),
366
),
@@ -1535,6 +1563,8 @@ export const ClientSettingsPatch = Schema.Struct({
1563
browserRecordingShowKeyPresses: Schema.optionalKey(Schema.Boolean),
1564
browserRecordingShowMousePresses: Schema.optionalKey(Schema.Boolean),
1565
browserLinkTarget: Schema.optionalKey(BrowserLinkTarget),
1566
+ browserSearchEngine: Schema.optionalKey(BrowserSearchEngine),
1567
+ browserCustomSearchUrl: Schema.optionalKey(BrowserCustomSearchUrl),
1568
browserAutoShowFloatingPreview: Schema.optionalKey(Schema.Boolean),
1569
browserProfiles: Schema.optionalKey(Schema.Array(BrowserProfile)),
1570
browserDefaultProfileId: Schema.optionalKey(BrowserProfileId),
packages/shared/src/preview.test.ts
+36
@@ -7,6 +7,7 @@ import {
7
PreviewUrlNormalizationError,
8
resolveAddressBarInput,
9
previewPdfAssetUrl,
10
+ resolveSearchUrlTemplate,
11
} from "./preview.ts";
12
13
describe("previewPdfAssetUrl", () => {
@@ -117,6 +118,41 @@ describe("resolveAddressBarInput", () => {
118
}
119
expect(resolveAddressBarInput("devbox:8080")).toBe("https://devbox:8080/");
120
});
121
+
122
+ it("searches with the given template and still opens addresses directly", () => {
123
+ const google = resolveSearchUrlTemplate({
124
+ browserSearchEngine: "google",
125
+ browserCustomSearchUrl: "",
126
+ });
127
+ expect(resolveAddressBarInput("how to center a div", google)).toBe(
128
+ "https://www.google.com/search?q=how%20to%20center%20a%20div",
129
+ );
130
+ expect(resolveAddressBarInput("cnn.com", google)).toBe("https://cnn.com/");
131
+ expect(resolveAddressBarInput("a&b", "https://search.example/?q=%s&lang=en")).toBe(
132
+ "https://search.example/?q=a%26b&lang=en",
133
+ );
134
+ });
135
+});
136
+
137
+describe("resolveSearchUrlTemplate", () => {
138
+ it("uses a valid custom template and falls back to DuckDuckGo for an unusable one", () => {
139
+ expect(
140
+ resolveSearchUrlTemplate({
141
+ browserSearchEngine: "custom",
142
+ browserCustomSearchUrl: " https://search.example/?q=%s ",
143
+ }),
144
+ ).toBe("https://search.example/?q=%s");
145
+ for (const browserCustomSearchUrl of [
146
+ "https://search.example/?q=",
147
+ "javascript:alert('%s')",
148
+ "https://%s.example.com/",
149
+ "https://%s@search.example/?q=%s",
150
+ ]) {
151
+ expect(
152
+ resolveSearchUrlTemplate({ browserSearchEngine: "custom", browserCustomSearchUrl }),
153
+ ).toBe("https://duckduckgo.com/?q=%s");
154
+ }
155
+ });
156
});
157
158
describe("newPreviewTabId", () => {
packages/shared/src/preview.ts
+55
-3
@@ -1,3 +1,4 @@
1
+import type { BrowserSearchEngine } from "@t3tools/contracts";
2
import * as Schema from "effect/Schema";
3
4
import { isLocalLoopbackHost } from "./hostClassification.ts";
@@ -75,7 +76,6 @@ function previewUrlProtocol(rawUrl: string): string | undefined {
76
return /^([A-Za-z][A-Za-z\d+.-]*):/.exec(rawUrl)?.[1]?.toLowerCase().concat(":");
77
}
78
78
-const SEARCH_URL = "https://duckduckgo.com/?q=";
79
const ADDRESS_HOST_PATTERN = /^(?:localhost|\d{1,3}(?:\.\d{1,3}){3}|\[[\da-f:.]+\])$/i;
80
const BARE_HOST_PORT_PATTERN = /^[^/?#:@]+:\d+(?:[/?#]|$)/;
81
const URL_SCHEME_WITH_AUTHORITY_PATTERN = /^[a-z][a-z\d+.-]*:\/\//i;
@@ -96,7 +96,59 @@ const KNOWN_NON_WEB_SCHEMES: ReadonlySet<string> = new Set([
96
"wss:",
97
]);
98
99
-export function resolveAddressBarInput(rawInput: string): string {
99
+/** Address bar search URL templates; `%s` is replaced with the encoded query. */
100
+const BROWSER_SEARCH_URL_TEMPLATES = {
101
+ duckduckgo: "https://duckduckgo.com/?q=%s",
102
+ google: "https://www.google.com/search?q=%s",
103
+ bing: "https://www.bing.com/search?q=%s",
104
+ brave: "https://search.brave.com/search?q=%s",
105
+ kagi: "https://kagi.com/search?q=%s",
106
+ ecosia: "https://www.ecosia.org/search?q=%s",
107
+} satisfies Record<Exclude<BrowserSearchEngine, "custom">, string>;
108
+
109
+function fillSearchUrlTemplate(template: string, query: string): string {
110
+ return template.replaceAll("%s", encodeURIComponent(query));
111
+}
112
+
113
+/**
114
+ * Whether a custom search URL is an http(s) URL with `%s` where the query goes.
115
+ * `%s` in the host or credentials is rejected: the query would never reach a
116
+ * search page, and a query with spaces would make the host unreachable.
117
+ */
118
+export function isValidSearchUrlTemplate(template: string): boolean {
119
+ if (!template.includes("%s")) return false;
120
+ try {
121
+ // Two queries land on different authorities only when `%s` sits before the path.
122
+ const authority = (url: URL) => `${url.username}:${url.password}@${url.host}`;
123
+ const url = new URL(fillSearchUrlTemplate(template, "a"));
124
+ const other = new URL(fillSearchUrlTemplate(template, "b"));
125
+ return (
126
+ (url.protocol === "http:" || url.protocol === "https:") && authority(url) === authority(other)
127
+ );
128
+ } catch {
129
+ return false;
130
+ }
131
+}
132
+
133
+/**
134
+ * The search URL template for the chosen engine. An unusable custom template
135
+ * falls back to DuckDuckGo so a query typed in the address bar always searches.
136
+ */
137
+export function resolveSearchUrlTemplate(settings: {
138
+ readonly browserSearchEngine: BrowserSearchEngine;
139
+ readonly browserCustomSearchUrl: string;
140
+}): string {
141
+ if (settings.browserSearchEngine !== "custom") {
142
+ return BROWSER_SEARCH_URL_TEMPLATES[settings.browserSearchEngine];
143
+ }
144
+ const custom = settings.browserCustomSearchUrl.trim();
145
+ return isValidSearchUrlTemplate(custom) ? custom : BROWSER_SEARCH_URL_TEMPLATES.duckduckgo;
146
+}
147
+
148
+export function resolveAddressBarInput(
149
+ rawInput: string,
150
+ searchUrlTemplate: string = BROWSER_SEARCH_URL_TEMPLATES.duckduckgo,
151
+): string {
152
const trimmed = rawInput.trim();
153
if (URL_SCHEME_WITH_AUTHORITY_PATTERN.test(trimmed) || trimmed.length === 0)
154
return normalizePreviewUrl(trimmed);
@@ -127,7 +179,7 @@ export function resolveAddressBarInput(rawInput: string): string {
179
} catch {}
180
}
181
}
130
- return `${SEARCH_URL}${encodeURIComponent(trimmed)}`;
182
+ return fillSearchUrlTemplate(searchUrlTemplate, trimmed);
183
}
184
185
export function normalizePreviewUrl(rawUrl: string): string {