feat(chrome): let the IDE agent use the user's Chrome and beta.42
The AITURK Chrome extension now registers the user's Chrome as the desktop backend's browser controller, the way the ChatGPT extension lets its agent work in the user's browser. The agent's existing browser tools (navigate, snapshot, click, type, scroll, back, press, get_images, vision) run in its own background tabs grouped as "AITURK", or a tab the user hands over. Backend: a local desktop lane in the browser-control broker. One controller registered from the loopback desktop transport is offered to every desktop session as a lane template; each session still gets its own exact scope on first use. The lane has its own switch (browser.extension_control.local_desktop, on by default); with no extension registered, or after it disconnects, the normal browser backend runs unchanged. browser_vision turns the extension's capture into the usual native/auxiliary vision result. Bridge: forwards controller commands only to a connection that registered, refuses unknown or oversized commands, relays results. Extension: service-worker controller with its own native connection, trusted chrome.debugger input (press/release only: a hover move waits 5 s on background tabs), refusal of password and payment-card fields and of browser, extension, file and Web Store pages, panel switch, Stop, tab hand-over, recent actions, Alt+Shift+A and right-click "send to AITURK". Cancelling Chrome's debugging bar stops the agent. Existing panel flows and privacy rules are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5c76c24c9c
commit
86a6621936
32 files changed
+2755
-195
No files matched your search
@@ -12,21 +12,33 @@ async function settle(condition) {
|
||||
assert.ok(condition(), 'UI did not settle')
|
||||
}
|
||||
|
||||
async function panel(t, respond) {
|
||||
const CONTROL_READY = { enabled: true, connected: true, registered: true, running: 0, tabs: [], shared: null,
|
||||
log: [{ status: 'ok', text: 'Sayfa açılıyor: example.test' }, { status: 'failed', text: '<b>Yazılıyor</b>', note: 'Şifre alanına ajan yazamaz.' }] }
|
||||
|
||||
async function panel(t, respond, { controlState = CONTROL_READY, session = {} } = {}) {
|
||||
const html = await readFile(new URL('../extension/panel.html', import.meta.url), 'utf8')
|
||||
const dom = new JSDOM(html, { url: 'https://extension-fixture.test/panel.html' })
|
||||
const calls = []
|
||||
const calls = [], controlCalls = []
|
||||
const port = { onMessage: eventHub(), onDisconnect: eventHub(), disconnect() {}, postMessage(message) {
|
||||
calls.push(message)
|
||||
queueMicrotask(() => respond(message, frame => port.onMessage.emit(frame), port))
|
||||
} }
|
||||
const runtimeMessages = eventHub()
|
||||
const sessionStore = { ...session }
|
||||
Object.assign(globalThis, { window: dom.window, document: dom.window.document, Option: dom.window.Option,
|
||||
chrome: { runtime: { connectNative: () => port }, storage: { local: { get: async () => ({}), set: async () => {} } } } })
|
||||
chrome: {
|
||||
runtime: { connectNative: () => port, onMessage: runtimeMessages,
|
||||
sendMessage: async message => { controlCalls.push(message); return message.type === 'control.set' ? { ...controlState, enabled: message.enabled } : controlState } },
|
||||
storage: { local: { get: async () => ({}), set: async () => {} }, onChanged: eventHub(),
|
||||
session: { get: async keys => Object.fromEntries([keys].flat().filter(key => key in sessionStore).map(key => [key, sessionStore[key]])),
|
||||
remove: async key => { delete sessionStore[key] }, set: async value => Object.assign(sessionStore, value) } },
|
||||
tabs: { get: async id => ({ id, title: 'Kaynak sayfa', url: 'https://example.test/yazi?token=gizli#x' }) },
|
||||
} })
|
||||
await import(`../extension/panel.js?test=${Math.random()}`)
|
||||
t.after(() => { dom.window.close(); for (const key of ['window', 'document', 'Option', 'chrome']) delete globalThis[key] })
|
||||
const get = id => dom.window.document.getElementById(id)
|
||||
await settle(() => !get('sessions').disabled)
|
||||
return { dom, calls, port, get, async select(id) {
|
||||
return { dom, calls, controlCalls, runtimeMessages, port, get, async select(id) {
|
||||
get('sessions').value = id
|
||||
get('sessions').dispatchEvent(new dom.window.Event('change'))
|
||||
await settle(() => !get('sessions').disabled)
|
||||
@@ -101,3 +113,44 @@ test('explicit page capture excludes form values and strips URL credentials in q
|
||||
assert.equal(context.url, 'https://example.test/page')
|
||||
assert.equal(context.selection, false)
|
||||
})
|
||||
|
||||
test('agent control section shows the live state, never renders log text as HTML, and drives the background', async t => {
|
||||
const p = await panel(t, fixtureResponse)
|
||||
await settle(() => p.get('control-status').textContent.startsWith('Hazır'))
|
||||
assert.equal(p.get('control-enabled').checked, true)
|
||||
assert.equal(p.get('control-stop').hidden, true)
|
||||
assert.equal(p.get('control-log').querySelector('b'), null)
|
||||
assert.ok(p.get('control-log').textContent.includes('<b>Yazılıyor</b>'))
|
||||
assert.ok(p.get('control-log').textContent.includes('Şifre alanına ajan yazamaz.'))
|
||||
|
||||
p.runtimeMessages.emit({ type: 'control.state', state: { ...CONTROL_READY, running: 1 } })
|
||||
assert.equal(p.get('control-stop').hidden, false)
|
||||
assert.ok(p.get('control-status').textContent.includes('çalışıyor'))
|
||||
|
||||
await p.select('one')
|
||||
p.get('control-share').dispatchEvent(new p.dom.window.Event('click'))
|
||||
p.get('control-stop').dispatchEvent(new p.dom.window.Event('click'))
|
||||
p.get('control-enabled').checked = false
|
||||
p.get('control-enabled').dispatchEvent(new p.dom.window.Event('change'))
|
||||
await settle(() => p.controlCalls.some(call => call.type === 'control.set'))
|
||||
assert.deepEqual(p.controlCalls.find(call => call.type === 'control.share'), { type: 'control.share', sessionId: 'one' })
|
||||
assert.ok(p.controlCalls.some(call => call.type === 'control.stop'))
|
||||
assert.deepEqual(p.controlCalls.find(call => call.type === 'control.set'), { type: 'control.set', enabled: false })
|
||||
await settle(() => p.get('control-status').textContent.startsWith('Kapalı'))
|
||||
})
|
||||
|
||||
test('a selection sent from the right-click menu waits for the first conversation and drops URL secrets', async t => {
|
||||
const p = await panel(t, fixtureResponse, { session: { pendingContext: { kind: 'selection', tabId: 7, text: 'Seçilen paragraf', at: Date.now() } } })
|
||||
await settle(() => !p.get('attachment').hidden)
|
||||
assert.ok(p.get('attachment-label').textContent.includes('Seçim: Kaynak sayfa'))
|
||||
assert.ok(p.get('notice').textContent.includes('konuşması seçin'))
|
||||
await p.select('one')
|
||||
assert.equal(p.get('attachment').hidden, false, 'the first choice keeps the pending attachment')
|
||||
p.get('message').value = 'Bunu özetle'
|
||||
p.get('composer').dispatchEvent(new p.dom.window.Event('submit', { cancelable: true }))
|
||||
await settle(() => p.calls.some(call => call.action === 'message.send'))
|
||||
const sent = p.calls.find(call => call.action === 'message.send').params.text
|
||||
assert.ok(sent.includes('Seçilen paragraf'))
|
||||
assert.ok(sent.includes('https://example.test/yazi'))
|
||||
assert.ok(!sent.includes('token=gizli'))
|
||||
})
|
||||
Reference in new issue
Block a user