-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathweb-ext.config.ts
More file actions
92 lines (85 loc) 路 3.26 KB
/
Copy pathweb-ext.config.ts
File metadata and controls
92 lines (85 loc) 路 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { createHash } from 'node:crypto'
import { mkdirSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { basename, dirname, join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineWebExtConfig } from 'wxt'
const env = process.env
const configDir = dirname(fileURLToPath(import.meta.url))
/**
* Returns a worktree+package-scoped Chromium profile so two dev runs
* never share state (this extension vs the agent extension; one
* worktree vs another with the same basename).
*
* Label = worktree dir basename (eg. feat-foo-bar)
* Key = 8-char sha256 of this package's directory
* Result: /tmp/browseros-dev-<label>-<key>
*/
function defaultChromiumProfile(): string {
const worktreeRoot = resolve(configDir, '../../../..')
const label = sanitizeProfileLabel(basename(worktreeRoot)) || 'repo'
const key = createHash('sha256').update(configDir).digest('hex').slice(0, 8)
return join(tmpdir(), `browseros-dev-${label}-${key}`)
}
function sanitizeProfileLabel(value: string): string {
return value
.toLowerCase()
.replace(/[^a-z0-9_.]+/g, '-')
.replace(/^-+|-+$/g, '')
}
/**
* Honors an explicit BROWSEROS_USER_DATA_DIR override; otherwise
* falls back to the worktree-scoped default. Either way the dir is
* created up-front so Chromium doesn't refuse to start.
*/
function chromiumProfile(): string {
const configured = env.BROWSEROS_USER_DATA_DIR?.trim()
const profile = configured || defaultChromiumProfile()
mkdirSync(profile, { recursive: true })
return profile
}
function browserOSProduct(defaultProduct: 'browseros' | 'browserclaw') {
const product = env.BROWSEROS_PRODUCT?.trim() || defaultProduct
if (product !== 'browseros' && product !== 'browserclaw') {
throw new Error(
`BROWSEROS_PRODUCT must be browseros or browserclaw: ${product}`,
)
}
return product
}
const chromiumArgs = [
'--use-mock-keychain',
// web-ext 9.x launches Chromium with --disable-blink-features=AutomationControlled,
// which trips Chromium's "unsupported command-line flag" infobar. --test-type
// marks this as a dev browser and suppresses that banner.
'--test-type',
'--show-component-extension-options',
// The dev BrowserOS binary ships an MCP server on port 9100; this
// package brings its own BrowserClaw API server on port 9200,
// so disable the bundled one to avoid port + behaviour drift.
'--disable-browseros-server',
'--disable-browseros-extensions',
'--browseros-dock-icon=dev',
`--browseros-product=${browserOSProduct('browserclaw')}`,
]
if (env.BROWSEROS_CLAW_CDP_PORT) {
chromiumArgs.push(`--remote-debugging-port=${env.BROWSEROS_CLAW_CDP_PORT}`)
}
if (env.BROWSEROS_SERVER_PORT) {
chromiumArgs.push(`--browseros-mcp-port=${env.BROWSEROS_SERVER_PORT}`)
chromiumArgs.push(`--browseros-server-port=${env.BROWSEROS_SERVER_PORT}`)
// --disable-browseros-server means no proxy is running, so proxy
// port falls back to server port.
chromiumArgs.push(`--browseros-proxy-port=${env.BROWSEROS_SERVER_PORT}`)
}
export default defineWebExtConfig({
binaries: {
chrome:
env.BROWSEROS_BINARY ||
'/Applications/BrowserOS.app/Contents/MacOS/BrowserOS',
},
chromiumArgs,
chromiumProfile: chromiumProfile(),
keepProfileChanges: true,
startUrls: ['chrome://newtab'],
})