capybara-lightpanda 0.17.1 → 0.18.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 +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +1 -1
- data/lib/capybara/lightpanda/browser/navigation.rb +32 -7
- data/lib/capybara/lightpanda/browser/selenium_compat.rb +8 -2
- data/lib/capybara/lightpanda/browser.rb +21 -5
- data/lib/capybara/lightpanda/javascripts/predicates.js +17 -0
- data/lib/capybara/lightpanda/node.rb +17 -0
- data/lib/capybara/lightpanda/process.rb +18 -5
- data/lib/capybara/lightpanda/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9462d0c1ee74b98cb8422cd7cefd2f6b332ca792c13ebddfb60b9b609cf40d4c
|
|
4
|
+
data.tar.gz: 617842c42afe642ce0e9509199a990a4202437c6dbd4744899307bc973766095
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c5e7dd3c1e2ed78bfc47f060b28a60960dbea91b34e830f32d4f0630b478fe5dc960554bf7de2c1be565f1b71061e29517c6d164570f61230d49220a963cef17
|
|
7
|
+
data.tar.gz: f3fb19c8dba1b2e93755de720bc90e86cd51657ec80864f8cfd696ddcd89732d2921f6a159c3fde58215614f639122d54cff1de87d9054f4a2492492e36c774a
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.18.0] - 2026-11-16
|
|
4
|
+
|
|
5
|
+
> **Update Lightpanda before upgrading.** This release requires Lightpanda **1.0.4** or a nightly build ≥ 12015. The driver refuses anything older and names the version it found. Pin `1.0.4` for a reproducible browser. On Intel Macs, Lightpanda 1.0.3 crashes on the first HTTPS request; 1.0.4 fixes that.
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- **`visit` waits for the page's JavaScript.** With a recent Lightpanda, `visit` could return before deferred and module scripts (Stimulus controllers, Turbo) had run, when the page took more than 2 seconds to load. The next `click` or `fill_in` then hit a page whose handlers weren't attached yet and was silently lost. `visit` now waits until those scripts have run.
|
|
10
|
+
- **`send_keys` on a rich-text editor types after the existing text.** On a `contenteditable` element that already held text, `send_keys` used to type in front of it ("xEdit me" instead of "Edit mex"). It now appends, as Chrome and WebDriver do.
|
|
11
|
+
- **A page with an iframe no longer lets `visit` or `click` move on too early.** When an iframe (an embedded widget, a video, a tweet) finished loading before the page itself, `visit` and a `click` that navigated returned while the page's own scripts were still pending, so the next click could do nothing. Seen on Forem: the comment menu never opened. They now wait for the page itself.
|
|
12
|
+
- **Text failure messages say what was searched for.** When no element held the text, `find("li", text: "…")` failed with just `Unable to find css "li"`. It now reads `Unable to find visible css "li" with text "…"`, and `assert_selector` lists the elements it rejected ("Also found …").
|
|
13
|
+
|
|
3
14
|
## [0.17.1] - 2026-11-08
|
|
4
15
|
|
|
5
16
|
### Fixed
|
data/README.md
CHANGED
|
@@ -57,7 +57,7 @@ driven_by :lightpanda
|
|
|
57
57
|
> Lightpanda is a headless agentic browser, not a layout engine. External `<link rel="stylesheet">` **are** fetched and applied (the gem enables this by default), and `@media` / `window.matchMedia()` evaluate against the `window_size` you configure — so a mobile-only CTA gated by `@media (max-width: …)` resolves at the width you ask for. What's missing is *layout*: nothing reflows, `getBoundingClientRect` stays synthetic, and there is no real scroll. Specs that assert on pixel geometry, scrolling, or screenshots can't pass here, nor can the two that catch people out: a second browser tab and a menu revealed purely by CSS `:hover`. See [known limitations](https://navidemad.github.io/capybara-lightpanda/docs/#limits).
|
|
58
58
|
|
|
59
59
|
> [!TIP]
|
|
60
|
-
> For reproducible CI, pin the browser: `Capybara::Lightpanda::Binary.required_version = "1.0.
|
|
60
|
+
> For reproducible CI, pin the browser: `Capybara::Lightpanda::Binary.required_version = "1.0.4"` (the tagged release the gem's current floor is pinned to — nightly build 12015 is that release's commit). Without a pin the driver tracks Lightpanda's rolling `nightly` tag, which moves under you. See [Pinning the browser version](https://navidemad.github.io/capybara-lightpanda/docs/#pinning).
|
|
61
61
|
|
|
62
62
|
## Credits
|
|
63
63
|
|
|
@@ -122,8 +122,13 @@ module Capybara
|
|
|
122
122
|
|
|
123
123
|
# Common navigation lifecycle shared by `wait_for_page_load` (fresh
|
|
124
124
|
# `Page.navigate`) and `wait_for_navigation` (reload).
|
|
125
|
-
# Subscribes to
|
|
126
|
-
#
|
|
125
|
+
# Subscribes to the main frame's load, runs the trigger, waits briefly
|
|
126
|
+
# for it, falls back to readyState polling for the remaining budget.
|
|
127
|
+
# The load is Page.frameStoppedLoading for the main frame, which
|
|
128
|
+
# Lightpanda sends right after Page.loadEventFired: that one carries no
|
|
129
|
+
# frameId and comes for every frame, so an iframe that loaded first
|
|
130
|
+
# made `visit` return while the page's deferred scripts were pending
|
|
131
|
+
# (forem's comment dropdown; visit_readiness_test.rb).
|
|
127
132
|
# The handler is unsubscribed via `ensure` so a raising trigger doesn't
|
|
128
133
|
# leak a subscription onto the next navigation. Returns the deadline so
|
|
129
134
|
# the caller can decide whether to attempt crash recovery.
|
|
@@ -131,8 +136,8 @@ module Capybara
|
|
|
131
136
|
starting_url = safe_current_url
|
|
132
137
|
deadline = monotonic_time + @options.timeout
|
|
133
138
|
loaded = Utils::Event.new
|
|
134
|
-
handler = proc { loaded.set }
|
|
135
|
-
@client.on("Page.
|
|
139
|
+
handler = proc { |params| loaded.set if params["frameId"] == @target_id }
|
|
140
|
+
@client.on("Page.frameStoppedLoading", &handler)
|
|
136
141
|
|
|
137
142
|
begin
|
|
138
143
|
yield
|
|
@@ -142,7 +147,7 @@ module Capybara
|
|
|
142
147
|
poll_ready_state(remaining, loaded_event: loaded, starting_url: starting_url) if remaining.positive?
|
|
143
148
|
end
|
|
144
149
|
ensure
|
|
145
|
-
@client.off("Page.
|
|
150
|
+
@client.off("Page.frameStoppedLoading", handler)
|
|
146
151
|
end
|
|
147
152
|
|
|
148
153
|
deadline
|
|
@@ -169,7 +174,18 @@ module Capybara
|
|
|
169
174
|
# decide whether the session is recoverable.
|
|
170
175
|
end
|
|
171
176
|
|
|
172
|
-
|
|
177
|
+
# `d` says whether DOMContentLoaded has fired, read from the navigation
|
|
178
|
+
# timing entry (null when the page has none). Since Lightpanda #4554
|
|
179
|
+
# (11988) readyState is `interactive` from the end of parsing, while
|
|
180
|
+
# deferred and module scripts (Stimulus, Turbo) are still pending;
|
|
181
|
+
# DOMContentLoaded waits for them. Legacy `performance.timing` can't
|
|
182
|
+
# stand in: Lightpanda keeps every field at 0.
|
|
183
|
+
POLL_STATE_JS = <<~JS.delete("\n")
|
|
184
|
+
(function(){
|
|
185
|
+
var p=window.performance,e=p&&p.getEntriesByType?p.getEntriesByType("navigation")[0]:null;
|
|
186
|
+
return{r:document.readyState,u:location.href,d:e?e.domContentLoadedEventStart>0:null}
|
|
187
|
+
})()
|
|
188
|
+
JS
|
|
173
189
|
private_constant :POLL_STATE_JS
|
|
174
190
|
|
|
175
191
|
def page_ready?(cmd_timeout, starting_url)
|
|
@@ -183,10 +199,19 @@ module Capybara
|
|
|
183
199
|
return false unless state
|
|
184
200
|
|
|
185
201
|
url_changed = starting_url.nil? || state["u"] != starting_url
|
|
186
|
-
url_changed &&
|
|
202
|
+
url_changed && ready_state_loaded?(state["r"], state["d"])
|
|
187
203
|
rescue Error
|
|
188
204
|
false
|
|
189
205
|
end
|
|
206
|
+
|
|
207
|
+
# `interactive` still counts once DOMContentLoaded fired: a page whose
|
|
208
|
+
# load event never comes (a hanging subresource) is usable then, and
|
|
209
|
+
# must not cost the whole timeout. Without a timing entry, trust it.
|
|
210
|
+
def ready_state_loaded?(ready_state, dom_content_loaded)
|
|
211
|
+
return true if ready_state == "complete"
|
|
212
|
+
|
|
213
|
+
ready_state == "interactive" && dom_content_loaded != false
|
|
214
|
+
end
|
|
190
215
|
end
|
|
191
216
|
end
|
|
192
217
|
end
|
|
@@ -91,8 +91,14 @@ module Capybara
|
|
|
91
91
|
evaluate_async(script.to_s.strip, *, frame: frame_stack.last)
|
|
92
92
|
end
|
|
93
93
|
|
|
94
|
-
# Selenium's raw-CDP escape hatch,
|
|
95
|
-
# `page.driver.browser.execute_cdp(
|
|
94
|
+
# Selenium's raw-CDP escape hatch,
|
|
95
|
+
# `page.driver.browser.execute_cdp(method, **params)`. The parameters
|
|
96
|
+
# are Lightpanda's, not Chrome's: a suite's
|
|
97
|
+
# `execute_cdp("Network.setBlockedURLs", urls: [...])` gets InvalidParams,
|
|
98
|
+
# because Lightpanda takes only
|
|
99
|
+
# `urlPatterns: [{ urlPattern: "*.png", block: true }]`. That list is
|
|
100
|
+
# also browser-wide and survives `reset!`, so clear it
|
|
101
|
+
# (`urlPatterns: []`) when the test that set it is done.
|
|
96
102
|
# Scoped to the page session, matching Selenium — that covers the
|
|
97
103
|
# Page / Runtime / DOM / Network / Emulation domains a suite would
|
|
98
104
|
# reach for. Browser-scoped commands (Target.*, Browser.*) still go
|
|
@@ -319,6 +319,11 @@ module Capybara
|
|
|
319
319
|
return if @page_events_enabled
|
|
320
320
|
|
|
321
321
|
page_command("Page.enable")
|
|
322
|
+
# Page.domContentEventFired and Page.loadEventFired carry no frameId
|
|
323
|
+
# and Lightpanda sends them for every frame: an iframe's load reads
|
|
324
|
+
# as the page's. Page.lifecycleEvent names its frame, so readiness
|
|
325
|
+
# waits use it instead (see #subscribe_to_document_ready).
|
|
326
|
+
page_command("Page.setLifecycleEventsEnabled", enabled: true)
|
|
322
327
|
@page_events_enabled = true
|
|
323
328
|
end
|
|
324
329
|
|
|
@@ -684,9 +689,17 @@ module Capybara
|
|
|
684
689
|
end
|
|
685
690
|
|
|
686
691
|
# The new document's context exists before its deferred and module
|
|
687
|
-
# scripts have run: this event marks the end of that phase, at
|
|
688
|
-
#
|
|
689
|
-
# (load, the frame stopping, the document request failing).
|
|
692
|
+
# scripts have run: this event marks the end of that phase, at the main
|
|
693
|
+
# frame's DOMContentLoaded or anything later that proves it is over
|
|
694
|
+
# (load, the frame stopping, the document request failing). Only the
|
|
695
|
+
# main frame counts: Page.domContentEventFired/loadEventFired carry no
|
|
696
|
+
# frameId and Lightpanda also sends them for iframes, so an iframe that
|
|
697
|
+
# finished first ended this wait while the page's deferred scripts were
|
|
698
|
+
# still pending (visit_readiness_test.rb). Page.lifecycleEvent names its
|
|
699
|
+
# frame; enable_page_events turns it on.
|
|
700
|
+
MAIN_FRAME_READY_EVENTS = %w[DOMContentLoaded load].freeze
|
|
701
|
+
private_constant :MAIN_FRAME_READY_EVENTS
|
|
702
|
+
|
|
690
703
|
def subscribe_to_document_ready
|
|
691
704
|
@document_ready_event = Utils::Event.new
|
|
692
705
|
@document_ready_event.set
|
|
@@ -694,8 +707,11 @@ module Capybara
|
|
|
694
707
|
on("Page.frameStartedNavigating") do |params|
|
|
695
708
|
@document_ready_event.reset if main_frame_navigation_start?(params)
|
|
696
709
|
end
|
|
697
|
-
on("Page.
|
|
698
|
-
|
|
710
|
+
on("Page.lifecycleEvent") do |params|
|
|
711
|
+
next unless params["frameId"] == @target_id
|
|
712
|
+
|
|
713
|
+
@document_ready_event.set if MAIN_FRAME_READY_EVENTS.include?(params["name"])
|
|
714
|
+
end
|
|
699
715
|
on("Page.frameStoppedLoading") do |params|
|
|
700
716
|
@document_ready_event.set if params["frameId"] == @target_id
|
|
701
717
|
end
|
|
@@ -192,6 +192,8 @@ function visibleText(el) {
|
|
|
192
192
|
// indexed loops: an overridden map must never detach cache rows from node IDs.
|
|
193
193
|
var hintStringify = JSON.stringify;
|
|
194
194
|
var hintLowerCase = Function.prototype.call.bind(String.prototype.toLowerCase);
|
|
195
|
+
// Candidates kept when none holds the searched text (see findHints).
|
|
196
|
+
var HINT_FAILURE_CANDIDATES = 10;
|
|
195
197
|
|
|
196
198
|
// Capybara keeps Result candidates for lazy enumeration, possibly after the DOM
|
|
197
199
|
// changes. Only immutable tag names belong in initial_cache; mutable visibility,
|
|
@@ -236,6 +238,21 @@ function findHints(nodes, spec) {
|
|
|
236
238
|
kept[kept.length] = el;
|
|
237
239
|
}
|
|
238
240
|
}
|
|
241
|
+
// No candidate holds the text: hand Capybara the first few anyway. It
|
|
242
|
+
// builds its failure message from the candidates it filtered out itself,
|
|
243
|
+
// so an empty array drops "visible"/"with text" and the "Also found" list.
|
|
244
|
+
// Capybara still rejects each one on its own text check, so results don't
|
|
245
|
+
// change. The cap bounds what a passing negative assertion pays: each kept
|
|
246
|
+
// candidate costs a visibility and a text read.
|
|
247
|
+
if (needles.length && kept.length === 0) {
|
|
248
|
+
var shown = nodes.length < HINT_FAILURE_CANDIDATES ? nodes.length : HINT_FAILURE_CANDIDATES;
|
|
249
|
+
for (var m = 0; m < shown; m++) {
|
|
250
|
+
var node = nodes[m];
|
|
251
|
+
hints[m] = { tag_name: node.nodeType === 11 ? 'ShadowRoot' :
|
|
252
|
+
(node.tagName ? hintLowerCase(node.tagName) : '') };
|
|
253
|
+
kept[m] = node;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
239
256
|
// Publish only after every read succeeds. Any exception returns the exact
|
|
240
257
|
// original array, without partial filtering or partially constructed hints.
|
|
241
258
|
kept.__lightpandaHints = hintStringify(hints);
|
|
@@ -1019,6 +1019,13 @@ module Capybara
|
|
|
1019
1019
|
# A non-focusable target (focus() is a no-op on those since upstream
|
|
1020
1020
|
# #3592, build 9646) must not leave the previous field focused, or its
|
|
1021
1021
|
# keys land there: blur it so they go to the body, as in Chrome.
|
|
1022
|
+
#
|
|
1023
|
+
# An editing host gets the same treatment: Lightpanda's focus() collapses
|
|
1024
|
+
# the caret at the host's first position (upstream #4538), so a draft
|
|
1025
|
+
# already in the editor took the keys in front of it. The caret goes
|
|
1026
|
+
# after the last non-blank text, inside its <p>, the position Chrome
|
|
1027
|
+
# normalizes WebDriver's collapsed end-of-contents range to; a host with
|
|
1028
|
+
# no text gets the end of its children.
|
|
1022
1029
|
SEND_KEYS_FOCUS_JS = <<~JS
|
|
1023
1030
|
function() {
|
|
1024
1031
|
var doc = this.ownerDocument;
|
|
@@ -1035,6 +1042,16 @@ module Capybara
|
|
|
1035
1042
|
var end = String(this.value || '').length;
|
|
1036
1043
|
this.setSelectionRange(end, end);
|
|
1037
1044
|
} catch (e) {}
|
|
1045
|
+
} else if (this.isContentEditable) {
|
|
1046
|
+
var sel = doc.defaultView && doc.defaultView.getSelection();
|
|
1047
|
+
if (!sel) return;
|
|
1048
|
+
var last = null;
|
|
1049
|
+
var walker = doc.createTreeWalker(this, 4 /* NodeFilter.SHOW_TEXT */);
|
|
1050
|
+
while (walker.nextNode()) {
|
|
1051
|
+
if (/\\S/.test(walker.currentNode.data)) last = walker.currentNode;
|
|
1052
|
+
}
|
|
1053
|
+
if (last) sel.collapse(last, last.data.length);
|
|
1054
|
+
else sel.collapse(this, this.childNodes.length);
|
|
1038
1055
|
}
|
|
1039
1056
|
}
|
|
1040
1057
|
JS
|
|
@@ -314,7 +314,20 @@ module Capybara
|
|
|
314
314
|
# (11012), ShadowRoot hit testing #4184 (11071), same-document
|
|
315
315
|
# navigateToHistoryEntry #3903 (11113), native isContentEditable #4210
|
|
316
316
|
# (11229), contenteditable Backspace/Delete/Ctrl+A #4415 (11610).
|
|
317
|
-
|
|
317
|
+
#
|
|
318
|
+
# 2026-11-16 bump 11647 -> 12015 (= release 1.0.4, the new lockstep cap;
|
|
319
|
+
# inert-aware hit testing #4548 at 12019 and xhr.upload events #4529 at
|
|
320
|
+
# 12116 stay above it). The reason: 1.0.3's x86_64-macos binary has no
|
|
321
|
+
# CPU baseline and dies with SIGILL on the first HTTPS request on CPUs
|
|
322
|
+
# without ADX (#4433); the baseline #4450 (11672) first ships in 1.0.4.
|
|
323
|
+
# Rides along: bad-port block #4430 (11651), CORS exposed headers #4242
|
|
324
|
+
# (11663), postMessage targetOrigin #4382 (11676), cross-site SameSite
|
|
325
|
+
# cookies #4442 (11688), multi-target CDP #3945 (11844), apple_m1 CPU pin
|
|
326
|
+
# #4533 (11915), readyState `interactive` before deferred scripts #4554
|
|
327
|
+
# (11988), CSS animation events opt-in #4559 (11991). No version gate
|
|
328
|
+
# sat between the two floors, so nothing is retired. Validated on the
|
|
329
|
+
# 1.0.4 aarch64-macos binary: test:all and spec:shared:parallel green.
|
|
330
|
+
MINIMUM_NIGHTLY_BUILD = Gem::Version.new("12015")
|
|
318
331
|
|
|
319
332
|
# Lines of browser output #output keeps (ferrum keeps the same 100).
|
|
320
333
|
OUTPUT_LINES = 100
|
|
@@ -326,16 +339,16 @@ module Capybara
|
|
|
326
339
|
# bare "0.3.6" carrying no commit counter at all, and MINIMUM_NIGHTLY_BUILD
|
|
327
340
|
# has nothing to compare against. Releases are cut from the same trunk, so
|
|
328
341
|
# a release is acceptable exactly when its own commit count clears the
|
|
329
|
-
# nightly floor. 1.0.
|
|
342
|
+
# nightly floor. 1.0.4 (2026-11-13) is build 12015 — exactly the nightly
|
|
330
343
|
# floor, which is no accident: the floor was raised *to* the release so
|
|
331
|
-
# both channels gate the same commit. (1.0.
|
|
332
|
-
# floor exists for.)
|
|
344
|
+
# both channels gate the same commit. (1.0.3 = 11647 predates the
|
|
345
|
+
# x86_64-macos CPU baseline the floor exists for.)
|
|
333
346
|
#
|
|
334
347
|
# INVARIANT: every MINIMUM_NIGHTLY_BUILD bump must also move this to the
|
|
335
348
|
# first release containing that build (`git rev-list --count <tag>` in the
|
|
336
349
|
# browser repo tells you). Leaving it behind would let the release channel
|
|
337
350
|
# silently accept a binary the nightly channel rejects.
|
|
338
|
-
MINIMUM_RELEASE = Gem::Version.new("1.0.
|
|
351
|
+
MINIMUM_RELEASE = Gem::Version.new("1.0.4")
|
|
339
352
|
|
|
340
353
|
# A release-candidate binary: "<x.y.z>-rc<N>.<git rev-list --count>+<hash>".
|
|
341
354
|
# Captures the commit counter.
|