kingai-browser 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kingai_browser-0.3.0/LICENSE +21 -0
- kingai_browser-0.3.0/MANIFEST.in +4 -0
- kingai_browser-0.3.0/PKG-INFO +123 -0
- kingai_browser-0.3.0/PYPI_README.md +109 -0
- kingai_browser-0.3.0/README.md +138 -0
- kingai_browser-0.3.0/README.zh-CN.md +138 -0
- kingai_browser-0.3.0/THIRD_PARTY_NOTICES.txt +33 -0
- kingai_browser-0.3.0/_kingai_async.py +115 -0
- kingai_browser-0.3.0/_kingai_automation.py +284 -0
- kingai_browser-0.3.0/_kingai_discovery.py +43 -0
- kingai_browser-0.3.0/_kingai_doctor.py +38 -0
- kingai_browser-0.3.0/_kingai_installer.py +113 -0
- kingai_browser-0.3.0/_kingai_stdio.py +271 -0
- kingai_browser-0.3.0/kingai_browser.egg-info/PKG-INFO +123 -0
- kingai_browser-0.3.0/kingai_browser.egg-info/SOURCES.txt +23 -0
- kingai_browser-0.3.0/kingai_browser.egg-info/dependency_links.txt +1 -0
- kingai_browser-0.3.0/kingai_browser.egg-info/entry_points.txt +2 -0
- kingai_browser-0.3.0/kingai_browser.egg-info/top_level.txt +7 -0
- kingai_browser-0.3.0/kingai_browser.py +383 -0
- kingai_browser-0.3.0/pyproject.toml +25 -0
- kingai_browser-0.3.0/setup.cfg +4 -0
- kingai_browser-0.3.0/tests/fixtures/async_saved_profile_navigation.py +19 -0
- kingai_browser-0.3.0/tests/fixtures/saved_profile_navigation.py +24 -0
- kingai_browser-0.3.0/tests/test_launch_ownership.py +99 -0
- kingai_browser-0.3.0/tests/test_samples.py +92 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 KingAI Browser contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kingai-browser
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Python code API for the installed KingAI stdio MCP server
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://www.kingaibrowser.cn
|
|
7
|
+
Project-URL: Repository, https://github.com/KingOX-cpp/KingAIBrowser
|
|
8
|
+
Project-URL: Issues, https://github.com/KingOX-cpp/KingAIBrowser/issues
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
License-File: THIRD_PARTY_NOTICES.txt
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# KingAI Browser Python SDK
|
|
16
|
+
|
|
17
|
+
Python 3.10+ client for KingAI Browser's installed stdio MCP server. Manage saved fingerprint environments and automate pages without Playwright or a separate HTTP service.
|
|
18
|
+
|
|
19
|
+
[Website](https://www.kingaibrowser.cn/) · [Alternative website](https://kingaibrowser.ccwu.cc/) · [Source and examples](https://github.com/KingOX-cpp/KingAIBrowser) · [Browser releases](https://github.com/KingOX-cpp/KingAIBrowser/releases)
|
|
20
|
+
|
|
21
|
+
## Install the SDK
|
|
22
|
+
|
|
23
|
+
```shell
|
|
24
|
+
python -m pip install kingai-browser
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The Python runtime library uses only the standard library. Browser installation and account login are separate from installing the SDK.
|
|
28
|
+
|
|
29
|
+
## Download the browser
|
|
30
|
+
|
|
31
|
+
```shell
|
|
32
|
+
python -m kingai_browser install
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Supports Windows Intel/AMD x64 and Apple Silicon macOS only. The explicit install command downloads and opens the Windows installer or macOS DMG; complete the installation UI yourself. It is not a silent installer. Open KingAI Manager and sign in after installation.
|
|
36
|
+
|
|
37
|
+
For download only:
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from kingai_browser import install
|
|
41
|
+
result = install(download_only=True)
|
|
42
|
+
print(result["status"], result["installerPath"])
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Windows downloads default to D:\code\KingAIBrowser-downloads; macOS uses ~/Downloads/KingAIBrowser. Set download_dir to an absolute path to change installer storage. It does not select the browser installation folder. HTTPS certificate verification remains enabled; IP certificate mismatches fail. Optional sha256 compares the installer to a trusted checksum supplied by the caller. A calculated hash alone is not authenticity verification.
|
|
46
|
+
|
|
47
|
+
## Locate MCP and diagnose
|
|
48
|
+
|
|
49
|
+
The SDK finds MCP using an explicit mcp_executable option, KINGAI_MCP_EXECUTABLE, or the per-user installation record written by a compatible Manager. KingAIMcpServer and KingAIRuntime must be installed together. The browser executable is not the MCP server.
|
|
50
|
+
|
|
51
|
+
```shell
|
|
52
|
+
python -m kingai_browser doctor
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Doctor reports installation discovery, MCP version and available tools without launching a browser. It does not verify Runtime compatibility or account login. Native stderr is forwarded to your terminal; redact sensitive information before sharing it.
|
|
56
|
+
|
|
57
|
+
## Open a saved environment
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from kingai_browser import launch
|
|
61
|
+
|
|
62
|
+
with launch() as browser:
|
|
63
|
+
browser.new_tab("https://example.com")
|
|
64
|
+
print(browser.read())
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The default is the existing unique saved profile named 默认环境. If it does not exist, explicitly select a saved profile with launch(profile_id="actual-profile-id") or create one using the management API. No temporary fallback is created.
|
|
68
|
+
|
|
69
|
+
Context exit detaches and releases the owned MCP connection while preserving the browser window. Explicit close_browser() closes the browser. After detaching, the original session cannot continue controlling that window; use Manager or explicitly attach a new authorized client to the active session.
|
|
70
|
+
|
|
71
|
+
## Profiles, DOM and input
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from kingai_browser import KingAI
|
|
75
|
+
|
|
76
|
+
with KingAI() as api:
|
|
77
|
+
print(api.profiles())
|
|
78
|
+
created = api.create_profile("My unique profile", language="en-US")
|
|
79
|
+
profile_id = created["profileId"]
|
|
80
|
+
api.update_profile(profile_id, name="My configured profile")
|
|
81
|
+
browser = api.start(profile_id=profile_id)
|
|
82
|
+
try:
|
|
83
|
+
browser.new_tab("https://example.com")
|
|
84
|
+
print(browser.snapshot(mode="interactive", limit=30))
|
|
85
|
+
print(browser.query(role="link", include_html=True, limit=10))
|
|
86
|
+
finally:
|
|
87
|
+
browser.detach()
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
On a page containing your target input/button, query its DOM and use a freshly observed ref:
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
matches = browser.query(selector="#name", limit=2)["elements"]
|
|
94
|
+
if len(matches) != 1:
|
|
95
|
+
raise RuntimeError("Expected one input")
|
|
96
|
+
browser.fill(ref=matches[0]["ref"], text="KingAI", humanize=False)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
This last fragment requires a live session and a page containing #name; example.com does not contain that input. Full runnable form examples and a local playground are in the source repository.
|
|
100
|
+
|
|
101
|
+
All installed MCP tools remain available through api.tools() and api.call(name, arguments). AsyncKingAI provides the async interface; BrowserAutomation provides an optional Agent action facade.
|
|
102
|
+
|
|
103
|
+
## Important behavior
|
|
104
|
+
|
|
105
|
+
- Update closed profiles only. Deletion requires explicit confirmation and removes saved data.
|
|
106
|
+
- Sessions operate on a selected tab. Serialize multi-step input workflows.
|
|
107
|
+
- Humanize requires valid account entitlement. Limits apply to concurrent open environments, not individual clicks.
|
|
108
|
+
- PAGE_NOT_VISIBLE requires restoring the window and activating the intended tab.
|
|
109
|
+
- A dispatched action is not proof of business completion. Independently observe the page result.
|
|
110
|
+
- Timeouts and observation errors do not automatically retry side effects.
|
|
111
|
+
- evaluate_preview provides bounded output and may truncate results.
|
|
112
|
+
|
|
113
|
+
Browser download/installation and real-site automation have not been validated as part of the first package publication. Installation/import checks do not establish browser compatibility or anti-detection performance.
|
|
114
|
+
|
|
115
|
+
## 中文说明
|
|
116
|
+
|
|
117
|
+
本包提供 Python 同步、异步调用,以及保存环境管理、DOM 观察、点击输入和通用 MCP 工具调用。先安装 SDK,再显式下载并完成浏览器安装、打开管理器登录。默认启动使用已存在的唯一“默认环境”,不会自动创建临时环境。with launch() 退出保留窗口;显式 close_browser() 才关闭浏览器。
|
|
118
|
+
|
|
119
|
+
完整中英文使用说明、示例和问题反馈请访问上述 GitHub 仓库。Windows 仅支持 Intel/AMD x64,Mac 仅支持 Apple 芯片。
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
MIT. Retain copyright, license and applicable third-party notices. This package contains client SDK code; third-party notices are included in the distribution.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# KingAI Browser Python SDK
|
|
2
|
+
|
|
3
|
+
Python 3.10+ client for KingAI Browser's installed stdio MCP server. Manage saved fingerprint environments and automate pages without Playwright or a separate HTTP service.
|
|
4
|
+
|
|
5
|
+
[Website](https://www.kingaibrowser.cn/) · [Alternative website](https://kingaibrowser.ccwu.cc/) · [Source and examples](https://github.com/KingOX-cpp/KingAIBrowser) · [Browser releases](https://github.com/KingOX-cpp/KingAIBrowser/releases)
|
|
6
|
+
|
|
7
|
+
## Install the SDK
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
python -m pip install kingai-browser
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The Python runtime library uses only the standard library. Browser installation and account login are separate from installing the SDK.
|
|
14
|
+
|
|
15
|
+
## Download the browser
|
|
16
|
+
|
|
17
|
+
```shell
|
|
18
|
+
python -m kingai_browser install
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Supports Windows Intel/AMD x64 and Apple Silicon macOS only. The explicit install command downloads and opens the Windows installer or macOS DMG; complete the installation UI yourself. It is not a silent installer. Open KingAI Manager and sign in after installation.
|
|
22
|
+
|
|
23
|
+
For download only:
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from kingai_browser import install
|
|
27
|
+
result = install(download_only=True)
|
|
28
|
+
print(result["status"], result["installerPath"])
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Windows downloads default to D:\code\KingAIBrowser-downloads; macOS uses ~/Downloads/KingAIBrowser. Set download_dir to an absolute path to change installer storage. It does not select the browser installation folder. HTTPS certificate verification remains enabled; IP certificate mismatches fail. Optional sha256 compares the installer to a trusted checksum supplied by the caller. A calculated hash alone is not authenticity verification.
|
|
32
|
+
|
|
33
|
+
## Locate MCP and diagnose
|
|
34
|
+
|
|
35
|
+
The SDK finds MCP using an explicit mcp_executable option, KINGAI_MCP_EXECUTABLE, or the per-user installation record written by a compatible Manager. KingAIMcpServer and KingAIRuntime must be installed together. The browser executable is not the MCP server.
|
|
36
|
+
|
|
37
|
+
```shell
|
|
38
|
+
python -m kingai_browser doctor
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Doctor reports installation discovery, MCP version and available tools without launching a browser. It does not verify Runtime compatibility or account login. Native stderr is forwarded to your terminal; redact sensitive information before sharing it.
|
|
42
|
+
|
|
43
|
+
## Open a saved environment
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from kingai_browser import launch
|
|
47
|
+
|
|
48
|
+
with launch() as browser:
|
|
49
|
+
browser.new_tab("https://example.com")
|
|
50
|
+
print(browser.read())
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The default is the existing unique saved profile named 默认环境. If it does not exist, explicitly select a saved profile with launch(profile_id="actual-profile-id") or create one using the management API. No temporary fallback is created.
|
|
54
|
+
|
|
55
|
+
Context exit detaches and releases the owned MCP connection while preserving the browser window. Explicit close_browser() closes the browser. After detaching, the original session cannot continue controlling that window; use Manager or explicitly attach a new authorized client to the active session.
|
|
56
|
+
|
|
57
|
+
## Profiles, DOM and input
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from kingai_browser import KingAI
|
|
61
|
+
|
|
62
|
+
with KingAI() as api:
|
|
63
|
+
print(api.profiles())
|
|
64
|
+
created = api.create_profile("My unique profile", language="en-US")
|
|
65
|
+
profile_id = created["profileId"]
|
|
66
|
+
api.update_profile(profile_id, name="My configured profile")
|
|
67
|
+
browser = api.start(profile_id=profile_id)
|
|
68
|
+
try:
|
|
69
|
+
browser.new_tab("https://example.com")
|
|
70
|
+
print(browser.snapshot(mode="interactive", limit=30))
|
|
71
|
+
print(browser.query(role="link", include_html=True, limit=10))
|
|
72
|
+
finally:
|
|
73
|
+
browser.detach()
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
On a page containing your target input/button, query its DOM and use a freshly observed ref:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
matches = browser.query(selector="#name", limit=2)["elements"]
|
|
80
|
+
if len(matches) != 1:
|
|
81
|
+
raise RuntimeError("Expected one input")
|
|
82
|
+
browser.fill(ref=matches[0]["ref"], text="KingAI", humanize=False)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
This last fragment requires a live session and a page containing #name; example.com does not contain that input. Full runnable form examples and a local playground are in the source repository.
|
|
86
|
+
|
|
87
|
+
All installed MCP tools remain available through api.tools() and api.call(name, arguments). AsyncKingAI provides the async interface; BrowserAutomation provides an optional Agent action facade.
|
|
88
|
+
|
|
89
|
+
## Important behavior
|
|
90
|
+
|
|
91
|
+
- Update closed profiles only. Deletion requires explicit confirmation and removes saved data.
|
|
92
|
+
- Sessions operate on a selected tab. Serialize multi-step input workflows.
|
|
93
|
+
- Humanize requires valid account entitlement. Limits apply to concurrent open environments, not individual clicks.
|
|
94
|
+
- PAGE_NOT_VISIBLE requires restoring the window and activating the intended tab.
|
|
95
|
+
- A dispatched action is not proof of business completion. Independently observe the page result.
|
|
96
|
+
- Timeouts and observation errors do not automatically retry side effects.
|
|
97
|
+
- evaluate_preview provides bounded output and may truncate results.
|
|
98
|
+
|
|
99
|
+
Browser download/installation and real-site automation have not been validated as part of the first package publication. Installation/import checks do not establish browser compatibility or anti-detection performance.
|
|
100
|
+
|
|
101
|
+
## 中文说明
|
|
102
|
+
|
|
103
|
+
本包提供 Python 同步、异步调用,以及保存环境管理、DOM 观察、点击输入和通用 MCP 工具调用。先安装 SDK,再显式下载并完成浏览器安装、打开管理器登录。默认启动使用已存在的唯一“默认环境”,不会自动创建临时环境。with launch() 退出保留窗口;显式 close_browser() 才关闭浏览器。
|
|
104
|
+
|
|
105
|
+
完整中英文使用说明、示例和问题反馈请访问上述 GitHub 仓库。Windows 仅支持 Intel/AMD x64,Mac 仅支持 Apple 芯片。
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
MIT. Retain copyright, license and applicable third-party notices. This package contains client SDK code; third-party notices are included in the distribution.
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# KingAI Python SDK guide
|
|
2
|
+
|
|
3
|
+
English | [简体中文](README.zh-CN.md) | [Project / 项目](../README.md)
|
|
4
|
+
|
|
5
|
+
**SDK 0.3.0 · MIT · Python 3.10+**
|
|
6
|
+
|
|
7
|
+
Calls the installed KingAI MCP over stdio. No HTTP service or Playwright is required. Install the browser, sign in and use matching MCP/Runtime components first.
|
|
8
|
+
|
|
9
|
+
Lifecycle update: Python launch contexts and Java automatic Session resource cleanup detach and preserve windows. Explicit browser shutdown uses Python close()/close_browser(), Node close()/closeBrowser(), Java closeBrowser(), or Go Close()/CloseBrowser(). New ownership cases and launch/doctor changes are unexecuted; the historical 17-test result does not cover them.
|
|
10
|
+
|
|
11
|
+
After disconnecting, the original Session can no longer operate the retained window. Close it in Manager, or discover the real active session through a new client and explicitly attach if authorized. No automatic reconnection occurs. Java closeBrowser() throws SESSION_DISCONNECTED if its client is closed.
|
|
12
|
+
|
|
13
|
+
## Download the browser installer
|
|
14
|
+
|
|
15
|
+
Supports Windows Intel/AMD x64 and Apple Silicon macOS only, not Windows ARM, 32-bit Windows or Intel Mac. Each language has a native downloader. Explicit install calls can download and open the installer/DMG; finish its UI steps yourself. This is not silent installation.
|
|
16
|
+
|
|
17
|
+
```powershell
|
|
18
|
+
python -m kingai_browser install --download-only
|
|
19
|
+
# Download and open the installer UI
|
|
20
|
+
python -m kingai_browser install
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from kingai_browser import install
|
|
25
|
+
result = install(download_only=True)
|
|
26
|
+
print(result["status"], result["installerPath"])
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Windows downloads default to D:. The download directory is not the browser installation directory. TLS verification stays enabled; invalid/mismatched IP certificates fail. Supply a trusted SHA-256 to verify the payload. After installation, open Manager, sign in and run doctor. No installer was downloaded or executed, and no build/check/test was run in this change.
|
|
30
|
+
|
|
31
|
+
[Full installation guide](../INSTALLATION.md)
|
|
32
|
+
|
|
33
|
+
## Quick entry: launch
|
|
34
|
+
|
|
35
|
+
After installation and login, this entry discovers/connects MCP and starts a saved profile. The default must already exist; no missing-profile fallback is created.
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from kingai_browser import launch
|
|
39
|
+
|
|
40
|
+
browser = launch() # Existing unique default environment
|
|
41
|
+
try:
|
|
42
|
+
browser.new_tab("https://example.com")
|
|
43
|
+
print(browser.read())
|
|
44
|
+
finally:
|
|
45
|
+
browser.detach()
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The returned session owns its new client. Close closes the browser and releases MCP; detach preserves the browser and releases MCP; disconnect only releases the connection. Explicit-client APIs remain available.
|
|
49
|
+
|
|
50
|
+
[Troubleshooting / 故障排查](../TROUBLESHOOTING.md)
|
|
51
|
+
|
|
52
|
+
```powershell
|
|
53
|
+
python -m kingai_browser doctor
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Read-only diagnostics do not launch browsers. Login is unknown and Runtime unverified. MCP stderr is forwarded to the terminal, not stored in the report. CLI info falls back to basic metadata on older MCP versions.
|
|
57
|
+
|
|
58
|
+
## Installation and discovery
|
|
59
|
+
|
|
60
|
+
```powershell
|
|
61
|
+
python -m pip install --cache-dir D:/code/kingai-sdk-cache/pip ./python
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```powershell
|
|
65
|
+
$env:KINGAI_MCP_EXECUTABLE = 'D:\Apps\KingAIBrowser\KingAIMcpServer.exe'
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Replace the example path. Discovery uses an explicit SDK option, then the environment variable, then the Manager record. Do not pass the main browser executable. Keep caches, temporary files and outputs on D:. Public registry packages are not published.
|
|
69
|
+
|
|
70
|
+
## Start with a complete example
|
|
71
|
+
|
|
72
|
+
[Examples and prerequisites / 示例与前提](../examples/README.md) · [API recipes / 接口调用手册](../docs/API_EXAMPLES.md)
|
|
73
|
+
|
|
74
|
+
```powershell
|
|
75
|
+
# From repository root / 在仓库根目录,另开终端启动演示网页
|
|
76
|
+
python -m http.server 8765 --bind 127.0.0.1 --directory examples
|
|
77
|
+
# Then run in another terminal / 然后另开终端执行
|
|
78
|
+
python python/examples/browser_form_automation.py --live
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The complete workflow lists/creates/configures profiles, inspects DOM, queries refs, fills fields, clicks and independently confirms the result. Keep the window visible. Newly created profiles are retained.
|
|
82
|
+
|
|
83
|
+
## Calling pattern and results
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from kingai_browser import KingAI
|
|
87
|
+
|
|
88
|
+
with KingAI() as api:
|
|
89
|
+
profiles = api.profiles() # Saved environment summaries / 环境摘要
|
|
90
|
+
print(profiles)
|
|
91
|
+
profile = api.create_profile("My unique environment", language="en-US")
|
|
92
|
+
profile_id = profile["profileId"]
|
|
93
|
+
api.update_profile(profile_id, name="My configured environment")
|
|
94
|
+
browser = api.start(profile_id=profile_id)
|
|
95
|
+
try:
|
|
96
|
+
browser.new_tab("http://127.0.0.1:8765/demo.html")
|
|
97
|
+
browser.wait(selector="#name", state="visible")
|
|
98
|
+
print(browser.query(selector="#name", include_html=True))
|
|
99
|
+
browser.fill("#name", "KingAI", humanize=False)
|
|
100
|
+
print(browser.read())
|
|
101
|
+
finally:
|
|
102
|
+
browser.detach() # Keep window / 保留窗口
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`profileId` identifies saved environments; `sessionId` identifies a running session; `targetId` identifies a tab; `ref` identifies an observed element. / 四类 ID 分别代表环境、会话、标签和已观察元素,不可混用。
|
|
106
|
+
|
|
107
|
+
## API category map
|
|
108
|
+
|
|
109
|
+
| Category / 类别 | MCP tools / 工具 | Usage / 用途 |
|
|
110
|
+
| --- | --- | --- |
|
|
111
|
+
| Profiles / 环境 | `profiles_list`, `profiles_get`, `profiles_create`, `profiles_update`, `profiles_delete` | List summaries; create, inspect, configure a closed profile, explicitly delete. / 获取摘要、创建、读取、修改已关闭环境、显式删除。 |
|
|
112
|
+
| Sessions / 会话 | `browser_start`, `browser_sessions_list`, `browser_attach`, `browser_detach`, `browser_close` | Start by profile ID, discover active sessions, attach or detach. Close is destructive. / 按环境 ID 启动、查找和接入会话,区分断开与关闭。 |
|
|
113
|
+
| Tabs / 标签页 | `tabs_list`, `tabs_new`, `tabs_activate`, `tabs_close`, `browser_navigate` | Use returned targetId; activate before input. / 使用返回的 targetId,输入前激活目标标签。 |
|
|
114
|
+
| DOM / 页面 | `browser_read`, `browser_snapshot`, `browser_query`, `browser_wait` | Read text, inspect bounded DOM, obtain refs, wait for explicit conditions. / 读取文本、观察 DOM、取得 ref、等待明确条件。 |
|
|
115
|
+
| Input / 输入 | `browser_click`, `browser_fill`, `browser_type`, `browser_key`, `browser_scroll`, `browser_hover` | Fill replaces text; type appends. Query refs before action. / fill 替换,type 追加;先查询再操作。 |
|
|
116
|
+
| JavaScript / 求值 | `browser_evaluate` | Raw evaluation preserves results; preview is bounded and may truncate. / 原始求值与显式预览不同,预览可能截断。 |
|
|
117
|
+
| Artifacts / 产物 | `browser_screenshot`, `browser_pdf`, `browser_upload`, `browser_download` | Configure artifact/download roots and permitted upload paths. / 配置产物目录、下载目录和上传权限。 |
|
|
118
|
+
| State / 状态 | `cookies_list`, `storage_get` | Inspect local site state; never publish cookies or secrets. / 查看站点状态,不公开 Cookie 或秘密。 |
|
|
119
|
+
| Skills / 工作流 | `skills_list`, `skill_describe`, `skill_run`, `skill_status`, `skill_cancel`, `skill_runs_list` | Discover parameters before starting; poll returned run ID. / 先发现参数,启动后用真实 run ID 查询。 |
|
|
120
|
+
| Discovery / 工具发现 | `sdk_info`, `tools/list`, `runtime_request_status` | Installed schemas are authoritative; Runtime IDs are not JSON-RPC IDs. / 以安装版 schema 为准,区分 Runtime ID 与 JSON-RPC ID。 |
|
|
121
|
+
|
|
122
|
+
Every installed tool is available through generic `call` / `Call`; convenience methods differ by language. Use the recipes for exact argument examples and inspect `tools/list` for required fields. / 所有安装版工具都能经通用调用访问,便利方法并非每种语言完全相同;参数示例见手册,必填项以安装版 schema 为准。
|
|
123
|
+
|
|
124
|
+
## Lifecycle, errors and permissions
|
|
125
|
+
|
|
126
|
+
- Client close disconnects MCP; session close closes the browser. Detach keeps the browser available. / 客户端关闭、会话断开和浏览器关闭含义不同。
|
|
127
|
+
- Default start requires an existing unique 默认环境; it does not create one. / 默认启动不会自动创建缺失环境。
|
|
128
|
+
- Update only closed profiles; deletion requires explicit confirmation and removes persistent data. / 更新前关闭环境;删除需确认且会移除持久数据。
|
|
129
|
+
- Side effects are not automatically retried after timeout or observation failure. / 超时和观察失败不自动重放输入。
|
|
130
|
+
- Humanize needs valid entitlement; examples explicitly use false for basic form interaction. / 拟人化需要有效权益,演示显式关闭。
|
|
131
|
+
- PAGE_NOT_VISIBLE requires restoring the window and selecting the intended tab. / 页面不可见时恢复窗口并激活标签。
|
|
132
|
+
- Call sequences use one selected tab; serialize multi-step workflows. / 多步操作串行,不是 Playwright 多 Page 模型。
|
|
133
|
+
|
|
134
|
+
## Test scope and license
|
|
135
|
+
|
|
136
|
+
[SAMPLES.md](../SAMPLES.md) records earlier fixture tests. New examples, documentation and renames have not been built, checked or tested in this task. / 旧模拟测试不代表新增示例已实机验证;本轮未运行构建、检查或测试。
|
|
137
|
+
|
|
138
|
+
MIT: retain copyright/license and applicable third-party notices. / 允许传播、修改与商用,保留版权、许可及适用的第三方声明。
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# KingAI Python 使用说明
|
|
2
|
+
|
|
3
|
+
[English](README.md) | 简体中文 | [Project / 项目](../README.md)
|
|
4
|
+
|
|
5
|
+
**SDK 0.3.0 · MIT · Python 3.10+**
|
|
6
|
+
|
|
7
|
+
本库通过 stdio 调用已安装的 KingAI MCP,不需要 HTTP 服务或 Playwright。先安装浏览器并登录,MCP/Runtime 必须支持所需工具。
|
|
8
|
+
|
|
9
|
+
生命周期更新:Python launch 上下文和 Java Session 自动资源退出会 detach 并保留窗口。显式关闭分别使用 Python close()/close_browser()、Node close()/closeBrowser()、Java closeBrowser()、Go Close()/CloseBrowser()。新增 ownership、launch、doctor 均未执行验证,历史 17 项测试不覆盖这些改动。
|
|
10
|
+
|
|
11
|
+
连接释放后,原 Session 对象不能继续操作保留窗口。可在 Manager 中关闭,或由新客户端发现真实会话、在授权允许时显式 attach 后关闭;SDK 不自动重连。Java closeBrowser() 在客户端已关闭时抛 SESSION_DISCONNECTED。
|
|
12
|
+
|
|
13
|
+
## 浏览器下载安装
|
|
14
|
+
|
|
15
|
+
支持 Windows Intel/AMD x64 和 Apple 芯片 Mac,不支持 Windows ARM、32 位 Windows 或 Intel Mac。四语言均提供原生下载实现;显式安装命令可下载并打开安装向导/DMG,仍需用户完成安装,不是静默安装。
|
|
16
|
+
|
|
17
|
+
```powershell
|
|
18
|
+
python -m kingai_browser install --download-only
|
|
19
|
+
# Download and open the installer UI
|
|
20
|
+
python -m kingai_browser install
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from kingai_browser import install
|
|
25
|
+
result = install(download_only=True)
|
|
26
|
+
print(result["status"], result["installerPath"])
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Windows 默认下载到 D 盘;下载目录不是浏览器安装目录。证书校验保持开启,IP 证书不可信或不匹配会失败;可传可信 SHA-256 校验文件。安装后打开 Manager 登录并运行 doctor。新增下载/安装入口本轮未下载或执行安装包,未运行构建、检查或测试。
|
|
30
|
+
|
|
31
|
+
[完整安装说明](../INSTALLATION.zh-CN.md)
|
|
32
|
+
|
|
33
|
+
## 快速入口:launch
|
|
34
|
+
|
|
35
|
+
完成安装和登录后,下面的入口负责定位 MCP、连接并启动环境。默认只打开已有的唯一“默认环境”,不会自动创建缺失环境。
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from kingai_browser import launch
|
|
39
|
+
|
|
40
|
+
browser = launch() # Existing unique default environment
|
|
41
|
+
try:
|
|
42
|
+
browser.new_tab("https://example.com")
|
|
43
|
+
print(browser.read())
|
|
44
|
+
finally:
|
|
45
|
+
browser.detach()
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
返回的会话拥有新客户端。close 关闭浏览器并释放 MCP;detach 保留浏览器并释放 MCP;disconnect 仅释放连接。原有显式客户端 API 保持可用。
|
|
49
|
+
|
|
50
|
+
[Troubleshooting / 故障排查](../TROUBLESHOOTING.md)
|
|
51
|
+
|
|
52
|
+
```powershell
|
|
53
|
+
python -m kingai_browser doctor
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
只读诊断不启动浏览器;登录态显示 unknown,Runtime 未验证。MCP stderr 转发至终端,不存入报告。旧 MCP 缺少 sdk_info 时 CLI info 仍返回基础信息。
|
|
57
|
+
|
|
58
|
+
## 安装与定位
|
|
59
|
+
|
|
60
|
+
```powershell
|
|
61
|
+
python -m pip install --cache-dir D:/code/kingai-sdk-cache/pip ./python
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```powershell
|
|
65
|
+
$env:KINGAI_MCP_EXECUTABLE = 'D:\Apps\KingAIBrowser\KingAIMcpServer.exe'
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
示例路径需替换。定位顺序为显式 SDK 参数、环境变量、管理器登记。不能把浏览器主程序当 MCP。依赖、临时文件、缓存与构建输出放 D 盘。公共包尚未发布。
|
|
69
|
+
|
|
70
|
+
## 从完整示例开始
|
|
71
|
+
|
|
72
|
+
[Examples and prerequisites / 示例与前提](../examples/README.md) · [API recipes / 接口调用手册](../docs/API_EXAMPLES.md)
|
|
73
|
+
|
|
74
|
+
```powershell
|
|
75
|
+
# From repository root / 在仓库根目录,另开终端启动演示网页
|
|
76
|
+
python -m http.server 8765 --bind 127.0.0.1 --directory examples
|
|
77
|
+
# Then run in another terminal / 然后另开终端执行
|
|
78
|
+
python python/examples/browser_form_automation.py --live
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
完整流程展示环境列表、创建与设置、DOM 快照、元素查询、输入、点击、等待并核对结果。窗口需可见;生成的新环境在结束后保留。
|
|
82
|
+
|
|
83
|
+
## 调用结构与返回值
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from kingai_browser import KingAI
|
|
87
|
+
|
|
88
|
+
with KingAI() as api:
|
|
89
|
+
profiles = api.profiles() # Saved environment summaries / 环境摘要
|
|
90
|
+
print(profiles)
|
|
91
|
+
profile = api.create_profile("My unique environment", language="en-US")
|
|
92
|
+
profile_id = profile["profileId"]
|
|
93
|
+
api.update_profile(profile_id, name="My configured environment")
|
|
94
|
+
browser = api.start(profile_id=profile_id)
|
|
95
|
+
try:
|
|
96
|
+
browser.new_tab("http://127.0.0.1:8765/demo.html")
|
|
97
|
+
browser.wait(selector="#name", state="visible")
|
|
98
|
+
print(browser.query(selector="#name", include_html=True))
|
|
99
|
+
browser.fill("#name", "KingAI", humanize=False)
|
|
100
|
+
print(browser.read())
|
|
101
|
+
finally:
|
|
102
|
+
browser.detach() # Keep window / 保留窗口
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`profileId` identifies saved environments; `sessionId` identifies a running session; `targetId` identifies a tab; `ref` identifies an observed element. / 四类 ID 分别代表环境、会话、标签和已观察元素,不可混用。
|
|
106
|
+
|
|
107
|
+
## 接口类别导航
|
|
108
|
+
|
|
109
|
+
| Category / 类别 | MCP tools / 工具 | Usage / 用途 |
|
|
110
|
+
| --- | --- | --- |
|
|
111
|
+
| Profiles / 环境 | `profiles_list`, `profiles_get`, `profiles_create`, `profiles_update`, `profiles_delete` | List summaries; create, inspect, configure a closed profile, explicitly delete. / 获取摘要、创建、读取、修改已关闭环境、显式删除。 |
|
|
112
|
+
| Sessions / 会话 | `browser_start`, `browser_sessions_list`, `browser_attach`, `browser_detach`, `browser_close` | Start by profile ID, discover active sessions, attach or detach. Close is destructive. / 按环境 ID 启动、查找和接入会话,区分断开与关闭。 |
|
|
113
|
+
| Tabs / 标签页 | `tabs_list`, `tabs_new`, `tabs_activate`, `tabs_close`, `browser_navigate` | Use returned targetId; activate before input. / 使用返回的 targetId,输入前激活目标标签。 |
|
|
114
|
+
| DOM / 页面 | `browser_read`, `browser_snapshot`, `browser_query`, `browser_wait` | Read text, inspect bounded DOM, obtain refs, wait for explicit conditions. / 读取文本、观察 DOM、取得 ref、等待明确条件。 |
|
|
115
|
+
| Input / 输入 | `browser_click`, `browser_fill`, `browser_type`, `browser_key`, `browser_scroll`, `browser_hover` | Fill replaces text; type appends. Query refs before action. / fill 替换,type 追加;先查询再操作。 |
|
|
116
|
+
| JavaScript / 求值 | `browser_evaluate` | Raw evaluation preserves results; preview is bounded and may truncate. / 原始求值与显式预览不同,预览可能截断。 |
|
|
117
|
+
| Artifacts / 产物 | `browser_screenshot`, `browser_pdf`, `browser_upload`, `browser_download` | Configure artifact/download roots and permitted upload paths. / 配置产物目录、下载目录和上传权限。 |
|
|
118
|
+
| State / 状态 | `cookies_list`, `storage_get` | Inspect local site state; never publish cookies or secrets. / 查看站点状态,不公开 Cookie 或秘密。 |
|
|
119
|
+
| Skills / 工作流 | `skills_list`, `skill_describe`, `skill_run`, `skill_status`, `skill_cancel`, `skill_runs_list` | Discover parameters before starting; poll returned run ID. / 先发现参数,启动后用真实 run ID 查询。 |
|
|
120
|
+
| Discovery / 工具发现 | `sdk_info`, `tools/list`, `runtime_request_status` | Installed schemas are authoritative; Runtime IDs are not JSON-RPC IDs. / 以安装版 schema 为准,区分 Runtime ID 与 JSON-RPC ID。 |
|
|
121
|
+
|
|
122
|
+
Every installed tool is available through generic `call` / `Call`; convenience methods differ by language. Use the recipes for exact argument examples and inspect `tools/list` for required fields. / 所有安装版工具都能经通用调用访问,便利方法并非每种语言完全相同;参数示例见手册,必填项以安装版 schema 为准。
|
|
123
|
+
|
|
124
|
+
## 生命周期、错误与权限
|
|
125
|
+
|
|
126
|
+
- Client close disconnects MCP; session close closes the browser. Detach keeps the browser available. / 客户端关闭、会话断开和浏览器关闭含义不同。
|
|
127
|
+
- Default start requires an existing unique 默认环境; it does not create one. / 默认启动不会自动创建缺失环境。
|
|
128
|
+
- Update only closed profiles; deletion requires explicit confirmation and removes persistent data. / 更新前关闭环境;删除需确认且会移除持久数据。
|
|
129
|
+
- Side effects are not automatically retried after timeout or observation failure. / 超时和观察失败不自动重放输入。
|
|
130
|
+
- Humanize needs valid entitlement; examples explicitly use false for basic form interaction. / 拟人化需要有效权益,演示显式关闭。
|
|
131
|
+
- PAGE_NOT_VISIBLE requires restoring the window and selecting the intended tab. / 页面不可见时恢复窗口并激活标签。
|
|
132
|
+
- Call sequences use one selected tab; serialize multi-step workflows. / 多步操作串行,不是 Playwright 多 Page 模型。
|
|
133
|
+
|
|
134
|
+
## 测试范围与许可
|
|
135
|
+
|
|
136
|
+
[SAMPLES.md](../SAMPLES.md) records earlier fixture tests. New examples, documentation and renames have not been built, checked or tested in this task. / 旧模拟测试不代表新增示例已实机验证;本轮未运行构建、检查或测试。
|
|
137
|
+
|
|
138
|
+
MIT: retain copyright/license and applicable third-party notices. / 允许传播、修改与商用,保留版权、许可及适用的第三方声明。
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
Third-party and retained notices
|
|
2
|
+
|
|
3
|
+
The following Chromium BSD notice was included in the previous SDK distribution.
|
|
4
|
+
It is retained for any material to which it applies; it does not replace the MIT license for KingAI SDK code.
|
|
5
|
+
|
|
6
|
+
// Copyright 2015 The Chromium Authors
|
|
7
|
+
// Copyright 2026 KingAI Browser contributors
|
|
8
|
+
//
|
|
9
|
+
// Redistribution and use in source and binary forms, with or without
|
|
10
|
+
// modification, are permitted provided that the following conditions are
|
|
11
|
+
// met:
|
|
12
|
+
//
|
|
13
|
+
// * Redistributions of source code must retain the above copyright
|
|
14
|
+
// notice, this list of conditions and the following disclaimer.
|
|
15
|
+
// * Redistributions in binary form must reproduce the above
|
|
16
|
+
// copyright notice, this list of conditions and the following disclaimer
|
|
17
|
+
// in the documentation and/or other materials provided with the
|
|
18
|
+
// distribution.
|
|
19
|
+
// * Neither the name of Google LLC nor the names of its
|
|
20
|
+
// contributors may be used to endorse or promote products derived from
|
|
21
|
+
// this software without specific prior written permission.
|
|
22
|
+
//
|
|
23
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
24
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
25
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
26
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
27
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
28
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
29
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
30
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
31
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
32
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
33
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|