Use My Browser
Operate the user's real Chrome browser through Tampermonkey script injection. The agent runs JavaScript directly in the page context — sharing all cookies, sessions, and login state.
Setup
CODEBLOCK0
Then install the Tampermonkey userscript in Chrome. Green indicator at bottom-right = connected.
Tools
| Tool | Purpose |
|---|
| INLINECODE0 | Check connection, list connected tabs |
| INLINECODE1 |
Switch to tab matching URL pattern |
|
tmwd_navigate | Navigate current tab to URL |
|
tmwd_newtab | Open new tab |
|
tmwd_text | Get visible text of current page |
|
tmwd_elements | List interactive elements (buttons, links, inputs) |
|
tmwd_scan | Get simplified HTML |
|
tmwd_exec | Execute JavaScript in page context |
Workflow
Read a page
CODEBLOCK1
Navigate to URL
CODEBLOCK2
Click / fill / interact
CODEBLOCK3
Extract data
CODEBLOCK4
Read table data
CODEBLOCK5
Click by text match
CODEBLOCK6
Fill form with multiple fields
CODEBLOCK7
JS Patterns Quick Reference
| Action | Code |
|---|
| Click button | INLINECODE8 |
| Fill input |
var e=document.querySelector('#input'); e.value='x'; e.dispatchEvent(new Event('input',{bubbles:true})) |
| Select dropdown |
var s=document.querySelector('select'); s.value='opt1'; s.dispatchEvent(new Event('change',{bubbles:true})) |
| Check checkbox |
var c=document.querySelector('[type=checkbox]'); c.checked=true; c.dispatchEvent(new Event('change',{bubbles:true})) |
| Scroll to bottom |
window.scrollTo(0, document.body.scrollHeight) |
| Scroll to element |
document.querySelector('#target').scrollIntoView() |
| Wait for element |
return !!document.querySelector('.loaded') |
| Get current URL |
return location.href |
| Go back |
history.back() |
CSP Fallback
Some sites (X/Twitter, banking sites) block eval() via Content Security Policy. When tmwd_exec returns csp_blocked: true, fall back to the built-in browser tool:
CODEBLOCK8
Built-in browser uses CDP which bypasses CSP, but runs in a separate instance (no user login state — login once, profile is persisted).
Rule: always try tmwd first, fall back only on failure.
Troubleshooting
| Problem | Fix |
|---|
| "No connected tabs" | Check green indicator in Chrome bottom-right |
| Red indicator |
Refresh the page, userscript auto-reconnects |
|
el.click() no effect | Try
el.dispatchEvent(new MouseEvent('click',{bubbles:true})) |
| CSP blocks eval | Use
tmwd_text (no eval needed) or fall back to built-in browser |
Notes
- - All JS runs in page context — shares cookies, localStorage, login state
- INLINECODE24 is DOM-level, does not move the mouse cursor
- Cross-origin iframes cannot be accessed (same-origin policy)
- If page refreshes, the userscript auto-reconnects with the same sessionId
- Use
return in JS to send values back; without return there is no output - For React/Vue apps, always use
dispatchEvent after setting values — direct .value= alone won't trigger framework reactivity
使用我的浏览器
通过Tampermonkey脚本注入操作真实的Chrome浏览器。代理直接在页面上下文中运行JavaScript——共享所有Cookie、会话和登录状态。
设置
bash
openclaw plugins install openclaw-tmwd --registry https://registry.npmjs.org
然后在Chrome中安装Tampermonkey用户脚本。右下角绿色指示灯表示已连接。
工具
| 工具 | 用途 |
|---|
| tmwdstatus | 检查连接,列出已连接的标签页 |
| tmwdswitch |
切换到匹配URL模式的标签页 |
| tmwd_navigate | 将当前标签页导航到指定URL |
| tmwd_newtab | 打开新标签页 |
| tmwd_text | 获取当前页面的可见文本 |
| tmwd_elements | 列出可交互元素(按钮、链接、输入框) |
| tmwd_scan | 获取简化版HTML |
| tmwd_exec | 在页面上下文中执行JavaScript |
工作流程
读取页面
tmwd_status() # 验证连接
tmwd_switch(pattern=github.com) # 切换到目标标签页
tmwdtext(maxchars=5000) # 获取页面内容
导航到URL
tmwd_navigate(url=https://example.com)
tmwd_text()
点击/填写/交互
tmwd_exec(code=document.querySelector(#submit).click())
tmwd_exec(code=var e=document.querySelector(#email); e.value=user@example.com; e.dispatchEvent(new Event(input,{bubbles:true})))
提取数据
tmwd_exec(code=return document.querySelector(.content).innerText)
tmwd_exec(code=return Array.from(document.querySelectorAll(h2)).map(e=>e.textContent))
读取表格数据
tmwd_exec(code=var rows=document.querySelectorAll(table tr); var d=[]; rows.forEach(function(r){var c=[]; r.querySelectorAll(td,th).forEach(function(e){c.push(e.innerText.trim())}); if(c.length) d.push(c)}); return d)
按文本匹配点击
tmwd_exec(code=var btns=document.querySelectorAll(button); for(var i=0;i
填写多字段表单
tmwd_exec(code=var f={#username:admin,#email:a@b.com}; Object.keys(f).forEach(function(s){var e=document.querySelector(s); e.value=f[s]; e.dispatchEvent(new Event(input,{bubbles:true}))}))
JS模式快速参考
| 操作 | 代码 |
|---|
| 点击按钮 | document.querySelector(button.submit).click() |
| 填写输入框 |
var e=document.querySelector(#input); e.value=x; e.dispatchEvent(new Event(input,{bubbles:true})) |
| 选择下拉框 | var s=document.querySelector(select); s.value=opt1; s.dispatchEvent(new Event(change,{bubbles:true})) |
| 勾选复选框 | var c=document.querySelector([type=checkbox]); c.checked=true; c.dispatchEvent(new Event(change,{bubbles:true})) |
| 滚动到底部 | window.scrollTo(0, document.body.scrollHeight) |
| 滚动到元素 | document.querySelector(#target).scrollIntoView() |
| 等待元素出现 | return !!document.querySelector(.loaded) |
| 获取当前URL | return location.href |
| 返回上一页 | history.back() |
CSP回退方案
某些网站(X/Twitter、银行网站)通过内容安全策略阻止eval()。当tmwdexec返回cspblocked: true时,回退到内置的browser工具:
- 1. browser(action=open, profile=openclaw, url=)
- browser(action=snapshot, targetId=)
内置浏览器使用CDP绕过CSP,但在独立实例中运行(无用户登录状态——登录一次后,配置文件会持久保存)。
规则:始终优先尝试tmwd,仅在失败时回退。
故障排除
| 问题 | 解决方案 |
|---|
| 没有已连接的标签页 | 检查Chrome右下角的绿色指示灯 |
| 红色指示灯 |
刷新页面,用户脚本会自动重新连接 |
| el.click() 无效果 | 尝试 el.dispatchEvent(new MouseEvent(click,{bubbles:true})) |
| CSP阻止eval | 使用 tmwd_text(无需eval)或回退到内置浏览器 |
注意事项
- - 所有JS在页面上下文中运行——共享Cookie、localStorage、登录状态
- el.click() 是DOM级别的操作,不会移动鼠标光标
- 无法访问跨源iframe(同源策略限制)
- 如果页面刷新,用户脚本会使用相同的sessionId自动重新连接
- 在JS中使用 return 返回值;没有 return 则无输出
- 对于React/Vue应用,设置值后始终使用 dispatchEvent——仅直接使用 .value= 不会触发框架的响应式更新