browser-control-sdk 0.2.2
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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +18 -0
- data/docs/API.md +9 -0
- data/docs/THIRD-PARTY-LICENSES.txt +22 -0
- data/examples/browser.rb +2 -0
- data/lib/browser_control_sdk.rb +78 -0
- data/lib/native/BrowserControlBridge.dll +0 -0
- metadata +69 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 4c869a20d4d53b4253a30369b1664e68ee9cb9905447209a32d84aacae2f5cc6
|
|
4
|
+
data.tar.gz: e787d6e4a8f1523429467bfdba1fc0dabe7768aa8c208ee1be2329aca2e065e8
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 68fb3e2352ffb9df87d7e91eb39ef6962fa724c26dbd34abd053bea1f243e02749a81bdab0397c98d37d44f5655230ee9d37dbf422a89255ecd799969cf8bd90
|
|
7
|
+
data.tar.gz: 53d5498ef3c0b01581c9e94fbb10e4fa59fb6f37b9103bb35b7c2051c7a54e39fc97d1d9eae22ba348f0f759fd123713334f9e5594766f46f74e3344dfc23868
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TitanCSA
|
|
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.
|
data/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Browser Control SDK for Ruby
|
|
2
|
+
|
|
3
|
+
`gem install browser-control-sdk`
|
|
4
|
+
|
|
5
|
+
Requires Ruby 3.1+ on Windows x64 and the running BrowserControl application. The included native bridge communicates directly with its private named pipe. No Python or driver installation is required.
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
require 'browser_control_sdk'
|
|
9
|
+
BrowserControlSDK::Browser.connect do |browser|
|
|
10
|
+
p browser.info
|
|
11
|
+
tab = browser.new_tab
|
|
12
|
+
browser.navigate(tab.fetch('id'), 'https://example.com')
|
|
13
|
+
end
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Use `connect(endpoint: 'C:/path/to/private/endpoint.json')` to select one running instance. Without a path the native SDK discovers a responding instance for the current user. The endpoint contains a private authentication token; keep it private.
|
|
17
|
+
|
|
18
|
+
Every documented protocol operation is available through `browser.call(method, params, timeout_ms: 15000)`. See [API documentation](docs/API.md) and [example](examples/browser.rb). Call `close` if you do not use the block form.
|
data/docs/API.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Ruby API
|
|
2
|
+
|
|
3
|
+
`BrowserControlSDK::Browser.connect(endpoint: nil) { |browser| ... }` connects and confirms the running instance. The block form always closes the client. `close` is idempotent. Windows x64 is required.
|
|
4
|
+
|
|
5
|
+
`call(method, params = {}, timeout_ms: 15000)` returns parsed JSON. Parameters must be a Hash, timeout an integer from 1 to 120000 milliseconds. Each client serializes calls. Convenience methods: `info`, `tabs`, `new_tab(options = {})`, `navigate(tab_id, url, timeout_ms: 15000)`.
|
|
6
|
+
|
|
7
|
+
`BrowserControlSDK::Error` exposes `code` and `details`. A `result_unknown` error means the action may have executed; inspect state before retrying. No request is automatically retried. Transport request/response bounds and timeouts are those of the original C++ SDK (1 MiB request and 64 MiB reply). Ruby Integer preserves JSON integers without converting them to floating point.
|
|
8
|
+
|
|
9
|
+
The bridge source and C ABI are in the repository's `Browser-Control-SDK-C-ffi` directory. Native handles and returned buffers are released by the wrapper. BrowserControl itself is distributed separately; the gem never downloads or launches it.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
JSON for Modern C++
|
|
2
|
+
Copyright (c) 2013-2025 Niels Lohmann
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2026 TitanCSA
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
data/examples/browser.rb
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
require 'fiddle/import'
|
|
3
|
+
require 'thread'
|
|
4
|
+
module BrowserControlSDK
|
|
5
|
+
VERSION = '0.2.2'
|
|
6
|
+
class Error < StandardError
|
|
7
|
+
attr_reader :code, :details
|
|
8
|
+
def initialize(data)
|
|
9
|
+
@code = data.fetch('code', 'sdk_error'); @details = data.fetch('details', {})
|
|
10
|
+
super(data.fetch('message', @code))
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
module Native
|
|
14
|
+
extend Fiddle::Importer
|
|
15
|
+
raise LoadError, 'BrowserControlSDK requires Windows x64' unless RUBY_PLATFORM.match?(/mswin|mingw/) && Fiddle::SIZEOF_VOIDP == 8
|
|
16
|
+
dlload File.expand_path('native/BrowserControlBridge.dll', __dir__)
|
|
17
|
+
extern 'unsigned long long bcs_connect(const char*, void*)'
|
|
18
|
+
extern 'int bcs_call(unsigned long long, const char*, const char*, unsigned int, void*)'
|
|
19
|
+
extern 'void bcs_close(unsigned long long)'
|
|
20
|
+
extern 'void bcs_free(void*)'
|
|
21
|
+
def self.output
|
|
22
|
+
ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP, Fiddle::RUBY_FREE)
|
|
23
|
+
ptr[0, Fiddle::SIZEOF_VOIDP] = [0].pack('J'); ptr
|
|
24
|
+
end
|
|
25
|
+
def self.take(out)
|
|
26
|
+
address = out[0, Fiddle::SIZEOF_VOIDP].unpack1('J')
|
|
27
|
+
raise Error.new('code'=>'sdk_error', 'message'=>'Native SDK returned no response') if address.zero?
|
|
28
|
+
text = Fiddle::Pointer.new(address)
|
|
29
|
+
begin
|
|
30
|
+
JSON.parse(text.to_s.force_encoding(Encoding::UTF_8))
|
|
31
|
+
ensure
|
|
32
|
+
bcs_free(text)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
class Browser
|
|
37
|
+
def self.connect(endpoint: nil)
|
|
38
|
+
client = new(endpoint)
|
|
39
|
+
return client unless block_given?
|
|
40
|
+
begin
|
|
41
|
+
yield client
|
|
42
|
+
ensure
|
|
43
|
+
client.close
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
def initialize(endpoint = nil)
|
|
47
|
+
@mutex = Mutex.new
|
|
48
|
+
raise ArgumentError, 'Endpoint must be a String or nil' unless endpoint.nil? || endpoint.is_a?(String)
|
|
49
|
+
path = endpoint&.encode(Encoding::UTF_8)
|
|
50
|
+
raise ArgumentError, 'Endpoint contains a NUL byte' if path&.include?("\0")
|
|
51
|
+
out = Native.output; @handle = Native.bcs_connect(path, out)
|
|
52
|
+
raise Error.new(Native.take(out)) if @handle.zero?
|
|
53
|
+
end
|
|
54
|
+
def call(method, params = {}, timeout_ms: 15_000)
|
|
55
|
+
raise ArgumentError, 'Parameters must be a Hash' unless params.is_a?(Hash)
|
|
56
|
+
raise ArgumentError, 'Use a nonempty method' unless method.is_a?(String) && !method.empty? && !method.include?("\0")
|
|
57
|
+
raise ArgumentError, 'Timeout must be 1..120000 milliseconds' unless timeout_ms.is_a?(Integer) && (1..120_000).cover?(timeout_ms)
|
|
58
|
+
@mutex.synchronize do
|
|
59
|
+
raise Error.new('code'=>'closed', 'message'=>'Browser client is closed') if @handle.zero?
|
|
60
|
+
out = Native.output
|
|
61
|
+
code = Native.bcs_call(@handle, method.encode(Encoding::UTF_8), JSON.generate(params), timeout_ms, out)
|
|
62
|
+
data = Native.take(out)
|
|
63
|
+
raise Error.new(data) unless code.zero?
|
|
64
|
+
data
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
def info; call('browser.info'); end
|
|
68
|
+
def tabs; call('tabs.list'); end
|
|
69
|
+
def new_tab(options = {}); call('tabs.create', options); end
|
|
70
|
+
def navigate(tab, url, timeout_ms: 15_000)
|
|
71
|
+
call('page.navigate', {'tab'=>tab, 'url'=>url, 'wait'=>'load', 'timeout_ms'=>timeout_ms}, timeout_ms: timeout_ms)
|
|
72
|
+
end
|
|
73
|
+
def close
|
|
74
|
+
@mutex.synchronize { Native.bcs_close(@handle) unless @handle.zero?; @handle = 0 }
|
|
75
|
+
nil
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
Binary file
|
metadata
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: browser-control-sdk
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- TitanCSA
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: fiddle
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.1'
|
|
19
|
+
- - "<"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '2'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '1.1'
|
|
29
|
+
- - "<"
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '2'
|
|
32
|
+
description: Ruby bindings to the native BrowserControl SDK. All protocol methods,
|
|
33
|
+
bounded transport, UTF-8 JSON and structured errors. Windows x64 only; no Python
|
|
34
|
+
dependency.
|
|
35
|
+
executables: []
|
|
36
|
+
extensions: []
|
|
37
|
+
extra_rdoc_files: []
|
|
38
|
+
files:
|
|
39
|
+
- LICENSE
|
|
40
|
+
- README.md
|
|
41
|
+
- docs/API.md
|
|
42
|
+
- docs/THIRD-PARTY-LICENSES.txt
|
|
43
|
+
- examples/browser.rb
|
|
44
|
+
- lib/browser_control_sdk.rb
|
|
45
|
+
- lib/native/BrowserControlBridge.dll
|
|
46
|
+
homepage: https://github.com/TitanCSA/Browser-Control-SDK
|
|
47
|
+
licenses:
|
|
48
|
+
- MIT
|
|
49
|
+
metadata:
|
|
50
|
+
source_code_uri: https://github.com/TitanCSA/Browser-Control-SDK/tree/main/Browser-Control-SDK-Ruby-rubygems
|
|
51
|
+
documentation_uri: https://github.com/TitanCSA/Browser-Control-SDK/tree/main/Browser-Control-SDK-Ruby-rubygems/docs
|
|
52
|
+
rdoc_options: []
|
|
53
|
+
require_paths:
|
|
54
|
+
- lib
|
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '3.1'
|
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
|
+
requirements:
|
|
62
|
+
- - ">="
|
|
63
|
+
- !ruby/object:Gem::Version
|
|
64
|
+
version: '0'
|
|
65
|
+
requirements: []
|
|
66
|
+
rubygems_version: 4.0.20
|
|
67
|
+
specification_version: 4
|
|
68
|
+
summary: Direct Windows named-pipe SDK for BrowserControl
|
|
69
|
+
test_files: []
|