�?bb-browser daemon 銝剜憓� /api/fetch HTTP 頝舐嚗鈭瘚��其�銝�銝剜銵?fetch 霂瑟���銝?API 憭鈭�� CDP 餈�?tab 蝞∠��餉�嚗隞亥�典��敶�� Cookie�?
- 憭�唳��箇�霈暹嚗�乩蝙�?daemon �?CDP 餈�?TabStateManager
- �芸 tab 蝞∠�嚗��
ensurePageTarget�芸���撱箏��� tab - **�餃����?*嚗瘚��其�銝�銝剜銵��芸�箏蒂 Cookie �恕霂縑�?
- 蝏��悅嚗蝙�函�� Request/Response �悅嚗噶鈭輕�?
POST http://localhost:6666/api/fetch
{
"url": "https://example.com/api/data",
"method": "GET",
"body": "{\"key\":\"value\"}",
"headers": {
"Content-Type": "application/json",
"X-Custom-Header": "value"
},
"tabId": "a1b2"
}| � | 蝐餃� | 敹‵ | 霂湔� |
|---|---|---|---|
url |
string | �? | �格� URL嚗��撖寡楝敺��詨笆頝臬�嚗? |
method |
string | �? | HTTP �寞�嚗�霈?GET |
body |
string | �? | 霂瑟�雿�GET/HEAD 霂瑟�隡蕭�伐� |
headers |
object | �? | �芸�銋窈瘙仍 |
tabId |
string/number | �? | �� tab ID嚗� ID嚗�銝�摰��芸� |
{
"status": 200,
"contentType": "application/json",
"body": {
"data": "response data"
}
}{
"error": "Fetch error: Network request failed",
"hint": "Fetch �扯�憭梯揖"
}curl -X POST http://localhost:6666/api/fetch \
-H "Content-Type: application/json" \
-d '{
"url": "https://api.github.com/users/octocat"
}'curl -X POST http://localhost:6666/api/fetch \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/api/login",
"method": "POST",
"body": "{\"username\":\"user\",\"password\":\"pass\"}",
"headers": {
"Content-Type": "application/json"
}
}'curl -X POST http://localhost:6666/api/fetch \
-H "Content-Type: application/json" \
-d '{
"url": "https://www.reddit.com/api/me.json",
"tabId": "a1b2"
}'const fetch = require('node-fetch');
async function bbFetch(url, options = {}) {
const response = await fetch('http://localhost:6666/api/fetch', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
url,
method: options.method || 'GET',
body: options.body,
headers: options.headers,
tabId: options.tabId,
}),
});
return await response.json();
}
// 雿輻蝷箔�
const result = await bbFetch('https://api.github.com/users/octocat');
console.log(result.body);import requests
import json
def bb_fetch(url, method='GET', body=None, headers=None, tab_id=None):
"""�� bb-browser daemon �扯� fetch 霂瑟�"""
payload = {
'url': url,
'method': method,
}
if body:
payload['body'] = body
if headers:
payload['headers'] = headers
if tab_id:
payload['tabId'] = tab_id
response = requests.post(
'http://localhost:6666/api/fetch',
json=payload
)
return response.json()
# 雿輻蝷箔�
result = bb_fetch('https://api.github.com/users/octocat')
print(json.dumps(result['body'], indent=2))- �交霂瑟�嚗TTP ��冽�?
/api/fetchPOST 霂瑟� - 蝑� CDP 撠梁貌嚗&靽?Chrome 餈撌脣遣蝡?
- � tab嚗?
- 憒���鈭?
tabId嚗蝙�刻砲 tab - �血���
ensurePageTarget�芸���撱?tab
- 憒���鈭?
- �遣 fetch �嚗��瘚��其葉�扯��?JavaScript 隞��
- �扯�霂瑟�嚗�� CDP �?
Runtime.evaluate�?tab 銝剜銵? - 餈�蝏�嚗圾��摨僎餈�蝏��冽
| �寞�? | CLI bb-browser fetch |
HTTP API /api/fetch |
|---|---|---|
| 靚�孵� | �賭誘銵? | HTTP POST |
| ��箸 | 鈭箇掩鈭支����祈��? | 蝔�����蝔��? |
| 颲�澆� | 蝏垢� | JSON |
| Tab 蝞∠� | �芸�寥��� | �舀��� tabId |
| 霈方� | �? | �舀� Bearer token |
-
霈方�嚗��?daemon �蔭鈭?token嚗�閬霂瑟�憭港葉瘛餃�嚗?
-H "Authorization: Bearer YOUR_TOKEN" -
CORS嚗PI 撌脤�蝵?CORS �捂頝典�霈輸
-
�砍霈輸嚗aemon 暺恕�
127.0.0.1嚗��砍�航挪�?
| �秤 | �� | 閫��寞� |
|---|---|---|
Missing url parameter |
霂瑟�雿撩撠?url 摮挾 | 蝖桐�霂瑟�� url |
Chrome not connected |
CDP �芾��? | �臬 Chrome 撟園��?daemon |
Fetch timeout |
霂瑟�頞 | 璉��亦�蝏�憓�頞�園 |
Fetch error: ... |
瘚��?fetch 憭梯揖 | 璉��?URL ��蝏�? |
- 餈憭嚗��函�� CDP WebSocket 餈
- Tab 憭嚗����霂瑟�隡��?tab
- 頞�批嚗�霈方��?30 蝘�
COMMAND_TIMEOUT嚗? - 撟嗅��舀�嚗��銝芸僎�窈瘙?
�航��撘箏��踝�
- 瘚���嚗�之�辣銝蝸
- 霂瑟��行嚗 fetch ��瘛餃��拙�
- 蝻��批嚗��摮��仿�蝵?
- 隞���舀�嚗�摰�隞��霈曄蔭
- ���箏嚗�券�霂仃韐亦�霂瑟�
packages/shared/src/protocol.ts- �悅摰�packages/daemon/src/command-dispatch.ts- �賭誘憭�packages/daemon/src/http-server.ts- HTTP 頝舐packages/cli/src/commands/fetch.ts- CLI 摰��?