Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Give a Bot an initial view and refuse snapshots during takeover

Fei2411b099dbb72498
diff --git a/app/src/bot-views.mjs b/app/src/bot-views.mjs
index 22a91225..565eb81b 100644
--- a/app/src/bot-views.mjs
+++ b/app/src/bot-views.mjs
@@ -106,7 +106,7 @@ export class BotViews {
})
this.#installDebugger(entry)
this.#onChange({ type: 'created', ...this.#state(entry) })
- if (url !== 'about:blank') void contents.loadURL(url).catch(() => {})
+ void contents.loadURL(url).catch(() => {})
return entry
}
@@ -183,6 +183,7 @@ export class BotViews {
async endpoint(botId) {
if (!this.#address) await new Promise(resolve => this.#server.once('listening', resolve))
+ if (this.sync(botId).length === 0) this.create(botId, { url: 'about:blank', createdByBot: true })
for (const [token, id] of this.#tokens) if (id === botId) this.#tokens.delete(token)
const token = randomBytes(32).toString('hex')
this.#tokens.set(token, botId)
diff --git a/app/test/bot-views.test.mjs b/app/test/bot-views.test.mjs
index 788fb700..1dde4a1e 100644
--- a/app/test/bot-views.test.mjs
+++ b/app/test/bot-views.test.mjs
@@ -15,6 +15,7 @@ function fixture() {
constructor() {
super()
this.url = 'about:blank'
+ this.loadedUrls = []
this.debugger = Object.assign(new EventEmitter(), {
attach() {},
async sendCommand(method) {
@@ -29,7 +30,7 @@ function fixture() {
canGoBack() { return false }
canGoForward() { return false }
isDestroyed() { return false }
- async loadURL(url) { this.url = url }
+ async loadURL(url) { this.url = url; this.loadedUrls.push(url) }
async executeJavaScript(script) { return script }
setWindowOpenHandler(handler) { this.windowOpenHandler = handler }
close() {}
@@ -83,6 +84,21 @@ function request(socket, id, method, params = {}, sessionId) {
})
}
+test('CDP endpoint creates and loads an initial view for a Bot with no tabs', async t => {
+ const { manager, views } = fixture()
+ t.after(() => manager.dispose())
+ const endpoint = await manager.endpoint('a')
+ assert.deepEqual(views[0].webContents.loadedUrls, ['about:blank'])
+ const socket = await openSocket(endpoint)
+ t.after(() => socket.close())
+
+ const targets = await request(socket, 1, 'Target.getTargets')
+ assert.equal(targets.result.targetInfos.length, 1)
+ assert.equal(targets.result.targetInfos[0].url, 'about:blank')
+ const info = await request(socket, 2, 'Target.getTargetInfo')
+ assert.equal(info.result.targetInfo.targetId, targets.result.targetInfos[0].targetId)
+})
+
test('CDP relay limits targets and created tabs to the token Bot', async t => {
const { manager, views } = fixture()
t.after(() => manager.dispose())
diff --git a/browser-plugins/test/write-safety.test.js b/browser-plugins/test/write-safety.test.js
index 3b1a0838..e0d0907e 100644
--- a/browser-plugins/test/write-safety.test.js
+++ b/browser-plugins/test/write-safety.test.js
@@ -229,6 +229,7 @@ test('Bot handoff can resume, but user takeover blocks browser actions until giv
hold = { by: 'user', reason: 'takeover', note: '' }
assert.throws(() => session.resume(), /Only the user can give it back/)
+ await assert.rejects(session.snapshotText(), /The user has taken over this browser/)
await assert.rejects(session.open(fixture.url), /The user has taken over this browser/)
hold = null
assert.match(await session.open(fixture.url), /Write safety/)
diff --git a/ds-bot/src/host/browser/session.js b/ds-bot/src/host/browser/session.js
index 7ccd5093..01658f87 100644
--- a/ds-bot/src/host/browser/session.js
+++ b/ds-bot/src/host/browser/session.js
@@ -206,6 +206,7 @@ function createSession({ context, browser, page, botId, userDataDir, cookieFile,
}
async function snapshotText({ observe = true } = {}) {
+ ready()
await pendingPageReady
const target = activePage()
if (!target) throw new Error('The browser has no open tabs.')