browserbeam 0.1.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15e5f1fad0f6f29ae8ce9616b429a9078771a1d6911a220e32b5f230c12ca02a
4
- data.tar.gz: 18116e46d6cabbc54716f800964ae354a993cead2f1c44d2edf0e97bbc1f2656
3
+ metadata.gz: 6b0481857f0872498c855f5c1cc7611f468f348e406299601fde653abb148487
4
+ data.tar.gz: 989f1e433800e1d2132cadb9bb83e8497884939da70deffe0e5148c21b74c647
5
5
  SHA512:
6
- metadata.gz: b8b82446fe2731ac36af5d52ee59706a43cc0e7214d404b066d472bb520cac5565a9eb04d1287858077b085e26bb0771f55cdfd3de3e63275e562859caeadd0b
7
- data.tar.gz: d5f19a469e10f1eb4ff9225c24e5bb44155504a26a6d936be209f48efa4bbc0f4a1c46516b25f7c540bacdfc83f04b1ba3a72ddce54318c11e0926a522204ae2
6
+ metadata.gz: 0605be53e22028d51513793fb6f0542caac9a131135ea1566fff865f7a5087f3c8b168569749fefc4cb1473f46b9e0accc22020c66495d4493caae72f46815f9
7
+ data.tar.gz: c5d700fbcac26e7757a891729071e7cb959007e0b4f8d8b7b51a16d34a145af168db7f108b726f0e24f67ed41f67d571c33db1d1992c76320a2091656fbb1764
data/README.md CHANGED
@@ -71,7 +71,7 @@ session = client.sessions.create(
71
71
  | Method | Description |
72
72
  |--------|-------------|
73
73
  | `session.goto(url)` | Navigate to a URL |
74
- | `session.observe` | Get page state as markdown |
74
+ | `session.observe` | Get page state as markdown. Supports `mode: "full"` for all sections. |
75
75
  | `session.click(ref:)` | Click an element by ref, text, or label |
76
76
  | `session.fill(value, ref:)` | Fill an input field |
77
77
  | `session.type(value, label:)` | Type text character by character |
@@ -84,9 +84,40 @@ session = client.sessions.create(
84
84
  | `session.fill_form(fields, submit:)` | Fill and submit a form |
85
85
  | `session.wait(ms:)` | Wait for time, selector, or text |
86
86
  | `session.pdf` | Generate a PDF |
87
- | `session.execute_js(expr)` | Run JavaScript |
87
+ | `session.execute_js(code)` | Run JavaScript |
88
88
  | `session.close` | Close the session |
89
89
 
90
+ ## Page Map & Full Mode
91
+
92
+ The first `observe` call automatically includes a `page.map` — a lightweight structural outline of the page's landmark regions (header, nav, main, aside, footer) with CSS selectors and descriptive hints. Use it to discover what content is available outside the main area.
93
+
94
+ ```ruby
95
+ res = session.observe
96
+ res.page.map.each { |entry| puts "#{entry.section}: #{entry.hint}" }
97
+ # nav: Home · Docs · Pricing
98
+ # main: Getting started with Browserbeam...
99
+ # aside: Related posts · Popular tags
100
+ ```
101
+
102
+ To re-request the map on subsequent calls:
103
+
104
+ ```ruby
105
+ session.observe(include_page_map: true)
106
+ ```
107
+
108
+ When you need content from **all** page sections (sidebars, footer links, nav items), use `mode: "full"`. The response markdown is organized by region headers:
109
+
110
+ ```ruby
111
+ full = session.observe(mode: "full", max_text_length: 20_000)
112
+ puts full.page.markdown.content
113
+ # ## [nav]
114
+ # Home · Docs · Pricing
115
+ # ## [main]
116
+ # ...article content...
117
+ # ## [aside]
118
+ # Related posts · ...
119
+ ```
120
+
90
121
  ## Session Management
91
122
 
92
123
  ```ruby
@@ -19,17 +19,20 @@ module Browserbeam
19
19
  envelope
20
20
  end
21
21
 
22
- def goto(url, wait_for: nil, wait_timeout: nil)
22
+ def goto(url, wait_for: nil, wait_until: nil, wait_timeout: nil)
23
23
  params = { url: url }
24
24
  params[:wait_for] = wait_for if wait_for
25
+ params[:wait_until] = wait_until if wait_until
25
26
  params[:wait_timeout] = wait_timeout if wait_timeout
26
27
  act([{ goto: params }])
27
28
  end
28
29
 
29
- def observe(scope: nil, format: nil, include_links: nil, max_text_length: nil)
30
+ def observe(scope: nil, format: nil, mode: nil, include_page_map: nil, include_links: nil, max_text_length: nil)
30
31
  params = {}
31
32
  params[:scope] = scope if scope
32
33
  params[:format] = format if format
34
+ params[:mode] = mode if mode
35
+ params[:include_page_map] = include_page_map unless include_page_map.nil?
33
36
  params[:include_links] = include_links unless include_links.nil?
34
37
  params[:max_text_length] = max_text_length if max_text_length
35
38
  act([{ observe: params }])
@@ -43,43 +46,49 @@ module Browserbeam
43
46
  act([{ click: params }])
44
47
  end
45
48
 
46
- def fill(value, ref: nil, label: nil)
49
+ def fill(value, ref: nil, text: nil, label: nil)
47
50
  params = { value: value }
48
51
  params[:ref] = ref if ref
52
+ params[:text] = text if text
49
53
  params[:label] = label if label
50
54
  act([{ fill: params }])
51
55
  end
52
56
 
53
- def type(value, label: nil, ref: nil, delay: nil)
57
+ def type(value, ref: nil, text: nil, label: nil, delay: nil)
54
58
  params = { value: value }
55
- params[:label] = label if label
56
59
  params[:ref] = ref if ref
60
+ params[:text] = text if text
61
+ params[:label] = label if label
57
62
  params[:delay] = delay if delay
58
63
  act([{ type: params }])
59
64
  end
60
65
 
61
- def select(value, label: nil, ref: nil)
66
+ def select(value, ref: nil, text: nil, label: nil)
62
67
  params = { value: value }
63
- params[:label] = label if label
64
68
  params[:ref] = ref if ref
69
+ params[:text] = text if text
70
+ params[:label] = label if label
65
71
  act([{ select: params }])
66
72
  end
67
73
 
68
- def check(label: nil, ref: nil, checked: nil)
74
+ def check(ref: nil, text: nil, label: nil, checked: nil)
69
75
  params = {}
70
- params[:label] = label if label
71
76
  params[:ref] = ref if ref
77
+ params[:text] = text if text
78
+ params[:label] = label if label
72
79
  params[:checked] = checked unless checked.nil?
73
80
  act([{ check: params }])
74
81
  end
75
82
 
76
- def scroll(to: nil, direction: nil, amount: nil, times: nil, ref: nil)
83
+ def scroll(to: nil, direction: nil, amount: nil, times: nil, ref: nil, text: nil, label: nil)
77
84
  params = {}
78
85
  params[:to] = to if to
79
86
  params[:direction] = direction if direction
80
87
  params[:amount] = amount if amount
81
88
  params[:times] = times if times
82
89
  params[:ref] = ref if ref
90
+ params[:text] = text if text
91
+ params[:label] = label if label
83
92
  act([{ scroll: params }])
84
93
  end
85
94
 
@@ -101,11 +110,12 @@ module Browserbeam
101
110
  act([{ screenshot: params }])
102
111
  end
103
112
 
104
- def wait(ms: nil, selector: nil, text: nil, timeout: nil)
113
+ def wait(ms: nil, selector: nil, text: nil, timeout: nil, **opts)
105
114
  params = {}
106
115
  params[:ms] = ms if ms
107
116
  params[:selector] = selector if selector
108
117
  params[:text] = text if text
118
+ params[:until] = opts[:until] if opts[:until]
109
119
  params[:timeout] = timeout if timeout
110
120
  act([{ wait: params }])
111
121
  end
@@ -120,20 +130,29 @@ module Browserbeam
120
130
  act([{ fill_form: params }])
121
131
  end
122
132
 
123
- def upload(ref, files)
124
- act([{ upload: { ref: ref, files: files } }])
133
+ def upload(files, ref: nil, text: nil, label: nil)
134
+ params = { files: files }
135
+ params[:ref] = ref if ref
136
+ params[:text] = text if text
137
+ params[:label] = label if label
138
+ act([{ upload: params }])
125
139
  end
126
140
 
127
- def pdf(format: nil, landscape: nil, print_background: nil)
141
+ def pdf(format: nil, landscape: nil, print_background: nil, scale: nil, margin: nil)
128
142
  params = {}
129
143
  params[:format] = format if format
130
144
  params[:landscape] = landscape unless landscape.nil?
131
145
  params[:print_background] = print_background unless print_background.nil?
146
+ params[:scale] = scale if scale
147
+ params[:margin] = margin if margin
132
148
  act([{ pdf: params }])
133
149
  end
134
150
 
135
- def execute_js(expression)
136
- act([{ execute_js: { expression: expression } }])
151
+ def execute_js(code, result_key: nil, timeout: nil)
152
+ params = { code: code }
153
+ params[:result_key] = result_key if result_key
154
+ params[:timeout] = timeout if timeout
155
+ act([{ execute_js: params }])
137
156
  end
138
157
 
139
158
  def close
@@ -18,6 +18,12 @@ module Browserbeam
18
18
  end
19
19
  end
20
20
 
21
+ MapEntry = Struct.new(:section, :selector, :hint, keyword_init: true) do
22
+ def self.from_hash(data)
23
+ new(section: data["section"] || "", selector: data["selector"] || "", hint: data["hint"] || "")
24
+ end
25
+ end
26
+
21
27
  Changes = Struct.new(:content_changed, :content_delta, :elements_added, :elements_removed, keyword_init: true) do
22
28
  def self.from_hash(data)
23
29
  return nil unless data.is_a?(Hash)
@@ -37,7 +43,7 @@ module Browserbeam
37
43
  end
38
44
  end
39
45
 
40
- PageState = Struct.new(:url, :title, :stable, :markdown, :interactive_elements, :forms, :changes, :scroll, keyword_init: true) do
46
+ PageState = Struct.new(:url, :title, :stable, :markdown, :map, :interactive_elements, :forms, :changes, :scroll, keyword_init: true) do
41
47
  def self.from_hash(data)
42
48
  return nil unless data.is_a?(Hash)
43
49
  new(
@@ -45,6 +51,7 @@ module Browserbeam
45
51
  title: data["title"] || "",
46
52
  stable: data["stable"] || false,
47
53
  markdown: MarkdownContent.from_hash(data["markdown"]),
54
+ map: data["map"] ? data["map"].map { |m| MapEntry.from_hash(m) } : nil,
48
55
  interactive_elements: (data["interactive_elements"] || []).map { |el| InteractiveElement.from_hash(el) },
49
56
  forms: data["forms"] || [],
50
57
  changes: Changes.from_hash(data["changes"]),
@@ -1,3 +1,3 @@
1
1
  module Browserbeam
2
- VERSION = "0.1.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browserbeam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Browserbeam
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-03-24 00:00:00.000000000 Z
11
+ date: 2026-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday