Files
Memoh/apps/browser/src/models.ts
T
Acbox Liu c8728ffc2c refactor(browser): split browser cores via build ARG, add core selector (#237)
* refactor(browser): split browser cores via build ARG, add core selector

- Replace playwright official image with ubuntu:noble base in both
  docker/Dockerfile.browser and devenv/Dockerfile.browser; install
  browsers at build time driven by ARG/ENV BROWSER_CORES
- Add GET /cores endpoint to Browser Gateway reporting available cores
- Proxy GET /browser-contexts/cores in Go handler to Browser Gateway
- Add `core` field to BrowserContextConfigModel and GatewayBrowserContext;
  context creation selects the appropriate browser instance by core
- Frontend context-setting page fetches available cores and renders a
  core selector; saves core as part of the config JSON
- install.sh prompts for browser core selection and writes BROWSER_CORES
  to .env; builds the browser image locally before docker compose up
- Regenerate OpenAPI spec and TypeScript SDK

* fix: lint
2026-03-14 12:37:20 +08:00

87 lines
2.1 KiB
TypeScript

import { z } from 'zod'
export const BrowserContextConfigModel = z.object({
core: z.enum(['chromium', 'firefox']).optional().default('chromium'),
viewport: z.object({
width: z.number(),
height: z.number(),
}).optional(),
userAgent: z.string().optional(),
deviceScaleFactor: z.number().optional(),
isMobile: z.boolean().optional(),
locale: z.string().optional(),
timezoneId: z.string().optional(),
geolocation: z.object({
latitude: z.number(),
longitude: z.number(),
accuracy: z.number().optional(),
}).optional(),
permissions: z.array(z.string()).optional(),
extraHTTPHeaders: z.record(z.string(), z.any()).optional(),
ignoreHTTPSErrors: z.boolean().optional(),
proxy: z.object({
server: z.string(),
bypass: z.string().optional(),
username: z.string().optional(),
password: z.string().optional(),
}).optional(),
})
export type BrowserContextConfig = z.infer<typeof BrowserContextConfigModel>
export const ActionRequestModel = z.object({
action: z.enum([
'navigate',
'click',
'dblclick',
'focus',
'type',
'fill',
'press',
'keyboard_type',
'keyboard_inserttext',
'keydown',
'keyup',
'hover',
'select',
'check',
'uncheck',
'screenshot',
'screenshot_annotate',
'snapshot',
'get_content',
'get_html',
'evaluate',
'scroll',
'scrollintoview',
'drag',
'upload',
'wait',
'go_back',
'go_forward',
'reload',
'get_url',
'get_title',
'pdf',
'tab_new',
'tab_select',
'tab_close',
'tab_list',
]),
url: z.string().optional(),
selector: z.string().optional(),
text: z.string().optional(),
script: z.string().optional(),
key: z.string().optional(),
value: z.string().optional(),
target_selector: z.string().optional(),
files: z.array(z.string()).optional(),
full_page: z.boolean().optional(),
tab_index: z.number().optional(),
direction: z.enum(['up', 'down', 'left', 'right']).optional(),
amount: z.number().optional(),
timeout: z.number().optional(),
})
export type ActionRequest = z.infer<typeof ActionRequestModel>