Tài liệu API đầy đủ cho hệ thống quản lý Profile trình duyệt
200 Lấy danh sách thành công
{
"success": true,
"data": [
{
"id": "abc123",
"name": "My Profile 1",
"proxy": "http:127.0.0.1:8080:user:pass",
"note": "Test profile",
"status": "stopped",
"who_running": null,
"debug_port": null,
...
},
{
"id": "xyz789",
"name": "My Profile 2",
"proxy": "socks5:127.0.0.1:9090:user:pass",
"note": "Another profile",
"status": "running",
"who_running": "machine-id-123",
"debug_port": 9222,
...
}
],
"message": "Lấy danh sách profile thành công"
}
curl -X GET "http://127.0.0.1:5678/rest/profiles"
const response = await fetch('http://127.0.0.1:5678/rest/profiles');
const data = await response.json();
console.log(data.data); // Array of profiles
import requests
response = requests.get('http://127.0.0.1:5678/rest/profiles')
profiles = response.json()
print(profiles['data'])
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| profile_name | string | Bắt buộc | Tên của profile cần tạo. |
| proxy | string | Không bắt buộc | Cấu hình proxy theo định dạng: http:ip:port:user:pass hoặc socks5:ip:port:user:pass hoặc ip:port:user:pass hoặc http:user:pass@ip:port hoặc socks5:user:pass@ip:port hoặc user:pass@ip:port hoặc http:ip:port hoặc socks5:ip:port hoặc ip:port |
| note | string | Không bắt buộc | Ghi chú bổ sung cho profile |
| extension | string | Không bắt buộc | Danh sách extension IDs hoặc đường dẫn local, ngăn cách bởi dấu xuống dòng |
200 Tạo profile thành công
{
"success": true,
"data": {
"profile_id": "abc123"
},
"message": "Tạo profile thành công"
}
200 Tạo profile thất bại
{
"success": false,
"data": {
"profile_id": null
},
"message": "Thông báo lỗi cụ thể"
}
curl -X GET "http://127.0.0.1:5678/rest/profiles/create?profile_name=My%20Profile&proxy=http:127.0.0.1:8080:user:pass¬e=Test%20profile"
const response = await fetch(
'http://127.0.0.1:5678/rest/profiles/create?' +
new URLSearchParams({
profile_name: 'My Profile',
proxy: 'http:127.0.0.1:8080:user:pass',
note: 'Test profile'
})
);
const data = await response.json();
console.log(data);
import requests
params = {
'profile_name': 'My Profile',
'proxy': 'http:127.0.0.1:8080:user:pass',
'note': 'Test profile'
}
response = requests.get('http://127.0.0.1:5678/rest/profiles/create', params=params)
print(response.json())
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| id | string | Bắt buộc | ID của profile cần cập nhật |
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| proxy | string | Không bắt buộc | Cấu hình proxy mới. Để trống để xóa proxy hiện tại. |
| note | string | Không bắt buộc | Ghi chú mới. Nếu không gửi, giữ nguyên ghi chú cũ. |
200 Cập nhật thành công
{
"success": true,
"data": {
"id": "abc123",
"name": "My Profile",
"proxy": "http:127.0.0.1:8080:user:pass",
"note": "Updated note",
...
},
"message": "Cập nhật profile thành công"
}
200 Cập nhật thất bại
{
"success": false,
"message": "Có lỗi xảy ra khi cập nhật profile"
}
curl -X PUT "http://127.0.0.1:5678/rest/profiles/abc123" \
-H "Content-Type: application/json" \
-d '{
"proxy": "http:127.0.0.1:9090:newuser:newpass",
"note": "Updated profile"
}'
const response = await fetch('http://127.0.0.1:5678/rest/profiles/abc123', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
proxy: 'http:127.0.0.1:9090:newuser:newpass',
note: 'Updated profile'
})
});
const data = await response.json();
console.log(data);
import requests
data = {
'proxy': 'http:127.0.0.1:9090:newuser:newpass',
'note': 'Updated profile'
}
response = requests.put('http://127.0.0.1:5678/rest/profiles/abc123', json=data)
print(response.json())
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| id | string | Bắt buộc | ID của profile cần xóa |
200 Xóa thành công
{
"success": true,
"message": "Xóa profile thành công"
}
200 Xóa thất bại
{
"success": false,
"message": "Có lỗi xảy ra khi xóa profile"
}
Thao tác xóa profile là không thể hoàn tác. Hãy chắc chắn bạn muốn xóa profile trước khi thực hiện.
curl -X DELETE "http://127.0.0.1:5678/rest/profiles/abc123"
const response = await fetch('http://127.0.0.1:5678/rest/profiles/abc123', {
method: 'DELETE'
});
const data = await response.json();
console.log(data);
import requests
response = requests.delete('http://127.0.0.1:5678/rest/profiles/abc123')
print(response.json())
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| id | string | Bắt buộc | ID của profile cần chạy |
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| win_scale | string | Không bắt buộc | Tỷ lệ zoom của cửa sổ (ví dụ: "1", "1.25") |
| win_pos | string | Không bắt buộc | Vị trí cửa sổ theo định dạng "x,y" (ví dụ: "100,100") |
| win_size | string | Không bắt buộc | Kích thước cửa sổ theo định dạng "width,height" (ví dụ: "1024,768") |
| source | string | Không bắt buộc | Chú ý: Truyền source="node" để tối ưu khi chạy automation, khi chạy profile từ giao diện thì để trống |
200 Chạy profile thành công
{
"success": true,
"data": {
"wsUrl": "ws://127.0.0.1:9222/devtools/browser/...",
"pid": 12345,
"debugPort": 9222,
"exePath": "C:\\path\\to\\chrome.exe",
"userDataDir": "C:\\path\\to\\profile\\data"
},
"message": "OK"
}
200 Chạy profile thất bại
{
"success": false,
"message": "Có lỗi xảy ra khi chạy profile"
}
curl -X GET "http://127.0.0.1:5678/rest/profiles/abc123/run?win_scale=1.25&win_pos=100,100&win_size=1024,768&source=node"
const params = new URLSearchParams({
win_scale: '1.25',
win_pos: '100,100',
win_size: '1024,768',
source: 'node'
});
const response = await fetch(
`http://127.0.0.1:5678/rest/profiles/abc123/run?${params}`
);
const data = await response.json();
console.log(data);
import requests
params = {
'win_scale': '1.25',
'win_pos': '100,100',
'win_size': '1024,768',
'source': 'node'
}
response = requests.get('http://127.0.0.1:5678/rest/profiles/abc123/run', params=params)
print(response.json())
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| id | string | Bắt buộc | ID của profile cần dừng |
200 Dừng profile thành công
{
"success": true,
"message": "Đóng thành công, profile id: abc123"
}
200 Các trường hợp lỗi
// Profile không tồn tại
{
"success": false,
"message": "Không tìm thấy profile"
}
// Profile không đang chạy
{
"success": false,
"message": "Profile không đang chạy"
}
// Profile đang chạy trên máy khác
{
"success": false,
"message": "Profile đang chạy trên máy khác"
}
// Lỗi khác
{
"success": false,
"message": "Có lỗi xảy ra khi đóng profile"
}
API này kiểm tra status và who_running của profile để đảm bảo chỉ có thể dừng profile đang chạy trên chính máy gọi API.
curl -X GET "http://127.0.0.1:5678/rest/profiles/abc123/stop"
const response = await fetch('http://127.0.0.1:5678/rest/profiles/abc123/stop');
const data = await response.json();
console.log(data);
import requests
response = requests.get('http://127.0.0.1:5678/rest/profiles/abc123/stop')
print(response.json())
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| id | string | Bắt buộc | ID của profile cần import cookies |
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| cookies | string | Bắt buộc | Chuỗi JSON chứa danh sách cookies cần import |
Cookies phải là một mảng JSON với mỗi phần tử chứa thông tin cookie:
[
{
"name": "session_id",
"value": "abc123xyz",
"domain": ".example.com",
"path": "/",
"secure": true,
"httpOnly": true,
"expirationDate": 1735689600
},
...
]
200 Import thành công
{
"success": true,
"message": "Cookies đã được import và merge thành công"
}
200 Import thất bại
// Profile không tồn tại
{
"success": false,
"message": "Profile không tồn tại"
}
// Định dạng cookies không hợp lệ
{
"success": false,
"message": "Định dạng cookies không hợp lệ"
}
// Lỗi khác
{
"success": false,
"message": "Có lỗi xảy ra khi import cookies"
}
- Cookies sẽ được merge với cookies hiện có, không ghi đè hoàn toàn.
- Nếu profile đang chạy trên máy này, cookies sẽ được load ngay vào trình duyệt thông qua debug port.
- Cookies được validate trước khi import.
curl -X POST "http://127.0.0.1:5678/rest/profiles/abc123/import-cookies" \
-H "Content-Type: application/json" \
-d '{
"cookies": "[{\"name\":\"session_id\",\"value\":\"abc123\",\"domain\":\".example.com\"}]"
}'
const cookies = [
{
name: 'session_id',
value: 'abc123',
domain: '.example.com',
path: '/',
secure: true
}
];
const response = await fetch('http://127.0.0.1:5678/rest/profiles/abc123/import-cookies', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
cookies: JSON.stringify(cookies)
})
});
const data = await response.json();
console.log(data);
import requests
import json
cookies = [
{
'name': 'session_id',
'value': 'abc123',
'domain': '.example.com',
'path': '/',
'secure': True
}
]
data = {
'cookies': json.dumps(cookies)
}
response = requests.post(
'http://127.0.0.1:5678/rest/profiles/abc123/import-cookies',
json=data
)
print(response.json())
| Tham số | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| id | string | Bắt buộc | ID của profile cần export cookies |
200 Export thành công
{
"success": true,
"data": [
{
"name": "session_id",
"value": "abc123xyz",
"domain": ".example.com",
"path": "/",
"secure": true,
"httpOnly": true,
"expirationDate": 1735689600
},
...
]
}
200 Export thất bại
// Không có cookies để export
{
"success": false,
"message": "Không có cookies để export"
}
// Lỗi khác
{
"success": false,
"message": "Chi tiết lỗi"
}
- Nếu profile đang chạy (status === 'running') và trên máy này (who_running === machineId), cookies được lấy từ trình duyệt qua debug port.
- Ngược lại, cookies được lấy từ trường cookies trong database.
curl -X GET "http://127.0.0.1:5678/rest/profiles/abc123/export-cookies"
const response = await fetch('http://127.0.0.1:5678/rest/profiles/abc123/export-cookies');
const result = await response.json();
if (result.success) {
console.log(result.data); // Array of cookies
} else {
console.error(result.message);
}
import requests
response = requests.get('http://127.0.0.1:5678/rest/profiles/abc123/export-cookies')
result = response.json()
if result['success']:
cookies = result['data']
print(cookies)
else:
print(result['message'])