dommy-rack 0.11.0 → 0.13.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 +17 -0
- data/lib/dommy/rack/session.rb +58 -6
- data/lib/dommy/rack/session_runtime.rb +46 -10
- data/lib/dommy/rack/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 641095671eb3c26567912daa210689bfcc8fdac11caf2e8416bfe6dde7b3dcbb
|
|
4
|
+
data.tar.gz: f8ce77ecd9791344cde9e93c806bc46767fac4f938c7ba0b669acbcddd1eec9a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2d8e8dab2d9ea2433194aff41cddef16aff29d46b7e808c2a161f2db9799d6dbb5a48a22597cefca26294a6e63c6fac61421d189b77d459be7982ae17ba49c72
|
|
7
|
+
data.tar.gz: 6d09efd87d9887d8858515479590d61cbd7eacfee55042e207c1ceefa99ba16f929845f4e51b0ce4c80621cb561725b9c53a587ed9613b1569545e6370798ec1
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.13.0 — 2026-09-23
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `Dommy::Rack::Session.new(app, strict_js_errors: true)` fails on JavaScript the page left unhandled, at the next point the page was allowed to run, so the failure lands on the line that caused it. Off by default.
|
|
8
|
+
- `Session#allow_js_errors { ... }` suppresses that failure for a block.
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- `js_errors` holds only what the page left unhandled: an error it cancels in `window.onerror` or in an `unhandledrejection` listener never reaches the log.
|
|
13
|
+
- The errors live in a shared `Dommy::Js::ErrorLog`, so an error the outgoing page left unreported survives the clear that navigation performs.
|
|
14
|
+
|
|
15
|
+
## 0.12.0 — 2026-09-22
|
|
16
|
+
|
|
17
|
+
Versioned in lockstep with [`dommy`](https://github.com/takahashim/dommy) 0.12.0.
|
|
18
|
+
No functional changes to dommy-rack itself.
|
|
19
|
+
|
|
3
20
|
## 0.11.0 — 2026-09-11
|
|
4
21
|
|
|
5
22
|
### Added
|
data/lib/dommy/rack/session.rb
CHANGED
|
@@ -78,6 +78,7 @@ module Dommy
|
|
|
78
78
|
follow_meta_refresh: true,
|
|
79
79
|
load_stylesheets: nil,
|
|
80
80
|
javascript: false,
|
|
81
|
+
strict_js_errors: false,
|
|
81
82
|
network_executor: nil,
|
|
82
83
|
cross_origin_subresources: :same_origin,
|
|
83
84
|
approximate_layout: false,
|
|
@@ -86,6 +87,10 @@ module Dommy
|
|
|
86
87
|
trace_dom: false,
|
|
87
88
|
trace_snapshots: false)
|
|
88
89
|
@app = app
|
|
90
|
+
# Fail on anything the page's JavaScript left unhandled, at the next
|
|
91
|
+
# checkpoint. Off by default so an embedding browser (which only reads
|
|
92
|
+
# `js_errors`) is unaffected; a test front end turns it on.
|
|
93
|
+
@strict_js_errors = strict_js_errors
|
|
89
94
|
# An optional off-thread network executor (responds to
|
|
90
95
|
# `submit(job) { |result| }`, e.g. dommynx's NetworkPool). When present,
|
|
91
96
|
# subresource fetch / XHR run on a worker and resolve via a
|
|
@@ -164,11 +169,16 @@ module Dommy
|
|
|
164
169
|
# Run JS for side effects against the current document's realm.
|
|
165
170
|
def execute_script(script)
|
|
166
171
|
require_js!.execute(script)
|
|
172
|
+
check_js_errors!
|
|
167
173
|
nil
|
|
168
174
|
end
|
|
169
175
|
|
|
170
176
|
# Evaluate JS and return the value (DOM nodes decoded to Dommy objects).
|
|
171
|
-
def evaluate_script(script)
|
|
177
|
+
def evaluate_script(script)
|
|
178
|
+
result = require_js!.evaluate(script)
|
|
179
|
+
check_js_errors!
|
|
180
|
+
result
|
|
181
|
+
end
|
|
172
182
|
|
|
173
183
|
# Settle work ready at the current virtual time (microtasks + due-now
|
|
174
184
|
# timers + requestAnimationFrame). A future setTimeout(ms) needs
|
|
@@ -176,27 +186,54 @@ module Dommy
|
|
|
176
186
|
def settle
|
|
177
187
|
require_js!.settle
|
|
178
188
|
__flush_page_navigation__
|
|
189
|
+
check_js_errors!
|
|
179
190
|
self
|
|
180
191
|
end
|
|
181
192
|
|
|
182
193
|
# Advance virtual time by `ms`, running timers that come due, then settle.
|
|
183
194
|
def advance_time(ms)
|
|
184
195
|
require_js!.advance_time(ms)
|
|
196
|
+
check_js_errors!
|
|
185
197
|
self
|
|
186
198
|
end
|
|
187
199
|
|
|
188
200
|
# Uncaught JS errors / unhandled rejections and console output collected
|
|
189
|
-
# by the JS runtime ([] when JS is disabled).
|
|
190
|
-
#
|
|
201
|
+
# by the JS runtime ([] when JS is disabled). Only what the PAGE left
|
|
202
|
+
# unhandled is here: an error it cancels in `window.onerror` never reaches
|
|
203
|
+
# the log, exactly as it stays out of a browser console.
|
|
191
204
|
def js_errors = @js_runtime ? @js_runtime.js_errors : []
|
|
192
205
|
def console = @js_runtime ? @js_runtime.console : []
|
|
193
206
|
|
|
207
|
+
# Suppress strict-mode failure for JS errors raised inside the block, for
|
|
208
|
+
# a test that triggers one on purpose. They stay in `js_errors`. A page
|
|
209
|
+
# that handles its own errors needs nothing here — it never reaches the
|
|
210
|
+
# log in the first place.
|
|
211
|
+
def allow_js_errors(&block)
|
|
212
|
+
return yield unless @js_runtime
|
|
213
|
+
|
|
214
|
+
@js_runtime.error_log.allow(&block)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
# Fail if the page left JS errors unhandled since the last checkpoint.
|
|
218
|
+
# Called at every point the page has just been allowed to run: after a
|
|
219
|
+
# navigation's scripts boot, after an interaction's events, after
|
|
220
|
+
# settle / advance_time / script evaluation, and at dispose. Each error is
|
|
221
|
+
# reported at most once (the ledger drains itself).
|
|
222
|
+
def check_js_errors!
|
|
223
|
+
@js_runtime&.error_log&.check!(context: @current_url)
|
|
224
|
+
end
|
|
225
|
+
|
|
194
226
|
# Full session teardown: the JS runtime(s) plus any live WebSocket
|
|
195
227
|
# transports. Safe to call when JS is disabled, and repeatedly.
|
|
228
|
+
# Tear the session down, then fail on anything the page left unhandled and
|
|
229
|
+
# nobody has reported. Disposing first means the failure cannot leave live
|
|
230
|
+
# realms behind.
|
|
196
231
|
def dispose
|
|
197
232
|
Array(@live_websocket_transports).each(&:dispose)
|
|
198
233
|
@live_websocket_transports = nil
|
|
234
|
+
log = @js_runtime&.error_log
|
|
199
235
|
dispose_js
|
|
236
|
+
log&.check!(context: @current_url)
|
|
200
237
|
end
|
|
201
238
|
|
|
202
239
|
# Dispose the JS runtime(s) only. Safe to call when JS is disabled.
|
|
@@ -322,6 +359,9 @@ module Dommy
|
|
|
322
359
|
@trace&.__internal_open_action(:visit, path)
|
|
323
360
|
result = @navigation.navigate(method: "GET", url: path)
|
|
324
361
|
self.settle if settle && @js_runtime
|
|
362
|
+
# `settle: false` observes the page mid-flight and settles nothing, but
|
|
363
|
+
# the new page's scripts have already booted, so a boot error is due now.
|
|
364
|
+
check_js_errors!
|
|
325
365
|
result
|
|
326
366
|
end
|
|
327
367
|
|
|
@@ -334,6 +374,7 @@ module Dommy
|
|
|
334
374
|
|
|
335
375
|
response, final_url = @navigation.run(**@last_request_args)
|
|
336
376
|
apply_navigation_response(response, final_url)
|
|
377
|
+
check_js_errors!
|
|
337
378
|
response
|
|
338
379
|
end
|
|
339
380
|
|
|
@@ -343,12 +384,20 @@ module Dommy
|
|
|
343
384
|
# visit runs, no full request; a target across a document boundary
|
|
344
385
|
# re-requests the URL. Returns the destination URL, or nil at the edge.
|
|
345
386
|
# A JS session may need `settle` afterwards for the restoration fetch.
|
|
387
|
+
# The checkpoint lives here rather than in traverse_history, which a
|
|
388
|
+
# page-initiated traversal also reaches from inside a drain: raising there
|
|
389
|
+
# would tear the drain down mid-flight instead of at the enclosing
|
|
390
|
+
# settle / after_interaction, which checks anyway.
|
|
346
391
|
def back
|
|
347
|
-
traverse_history(:back)
|
|
392
|
+
url = traverse_history(:back)
|
|
393
|
+
check_js_errors!
|
|
394
|
+
url
|
|
348
395
|
end
|
|
349
396
|
|
|
350
397
|
def forward
|
|
351
|
-
traverse_history(:forward)
|
|
398
|
+
url = traverse_history(:forward)
|
|
399
|
+
check_js_errors!
|
|
400
|
+
url
|
|
352
401
|
end
|
|
353
402
|
|
|
354
403
|
# --- NavigationDelegate port (see Dommy::Navigation) ---
|
|
@@ -877,6 +926,7 @@ module Dommy
|
|
|
877
926
|
def after_interaction
|
|
878
927
|
@js_runtime&.drain
|
|
879
928
|
__flush_page_navigation__
|
|
929
|
+
check_js_errors!
|
|
880
930
|
end
|
|
881
931
|
|
|
882
932
|
private
|
|
@@ -929,7 +979,9 @@ module Dommy
|
|
|
929
979
|
raise Error, "javascript: true requires dommy-js-quickjs " \
|
|
930
980
|
"(add the gem and `require \"dommy/js/quickjs/rack\"`)"
|
|
931
981
|
end
|
|
932
|
-
factory.call(self)
|
|
982
|
+
runtime = factory.call(self)
|
|
983
|
+
runtime.error_log.strict = @strict_js_errors if runtime.respond_to?(:error_log)
|
|
984
|
+
runtime
|
|
933
985
|
end
|
|
934
986
|
|
|
935
987
|
def require_js!
|
|
@@ -19,15 +19,21 @@ module Dommy
|
|
|
19
19
|
# `current_document` yields the document execute/evaluate should target
|
|
20
20
|
# (the session's current document by default; the Capybara driver passes
|
|
21
21
|
# its own frame-aware accessor).
|
|
22
|
-
#
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
# Console output collected across every realm.
|
|
23
|
+
attr_reader :console
|
|
24
|
+
|
|
25
|
+
# The ledger of errors the page left unhandled, across every realm. The
|
|
26
|
+
# Session drives its checkpoints; see Dommy::Js::ErrorLog.
|
|
27
|
+
attr_reader :error_log
|
|
25
28
|
|
|
26
29
|
def initialize(session, ¤t_document)
|
|
27
30
|
@session = session
|
|
28
31
|
@current_document = current_document || -> { session.document }
|
|
29
32
|
@runtimes = {}.compare_by_identity
|
|
30
|
-
|
|
33
|
+
# Non-strict by default: an embedding browser only reads the errors. A
|
|
34
|
+
# test front end turns strictness on through the owning Session, which
|
|
35
|
+
# is also what drives the checkpoints.
|
|
36
|
+
@error_log = ::Dommy::Js::ErrorLog.new(strict: false)
|
|
31
37
|
@console = []
|
|
32
38
|
@console_listeners = []
|
|
33
39
|
@js_error_listeners = []
|
|
@@ -41,6 +47,10 @@ module Dommy
|
|
|
41
47
|
# here, not on the Session — so the runtime fans them out. `on_document`
|
|
42
48
|
# fires before a freshly loaded page's scripts boot (see on_page_load), so
|
|
43
49
|
# a `:document` marker is ordered ahead of that page's `:script` entries.
|
|
50
|
+
# Uncaught JS errors and unhandled promise rejections the page did not
|
|
51
|
+
# handle, as a browser console's scrollback (cleared on navigation).
|
|
52
|
+
def js_errors = @error_log.errors
|
|
53
|
+
|
|
44
54
|
def on_console(&block) = @console_listeners << block
|
|
45
55
|
def on_js_error(&block) = @js_error_listeners << block
|
|
46
56
|
def on_script(&block) = @script_listeners << block
|
|
@@ -113,8 +123,10 @@ module Dommy
|
|
|
113
123
|
# own boot errors are retained. (An embedder that wants a running history
|
|
114
124
|
# keeps its own log; e.g. dommynx drains each page's output into its
|
|
115
125
|
# activity log before the next navigation.) Cleared in place so the Trace's
|
|
116
|
-
# separate live feed is unaffected.
|
|
117
|
-
|
|
126
|
+
# separate live feed is unaffected. Only the HISTORY goes: an error this
|
|
127
|
+
# page produced that nobody has reported yet still has to fail the test,
|
|
128
|
+
# so the ledger's unacknowledged queue survives the navigation.
|
|
129
|
+
@error_log.clear_history
|
|
118
130
|
@console.clear
|
|
119
131
|
dispose_all
|
|
120
132
|
# Announce the document BEFORE booting its scripts so a subscriber (the
|
|
@@ -126,11 +138,28 @@ module Dommy
|
|
|
126
138
|
|
|
127
139
|
def build_runtime(doc)
|
|
128
140
|
rt = Dommy::Js.build_runtime
|
|
129
|
-
|
|
130
|
-
|
|
141
|
+
window = doc&.default_view
|
|
142
|
+
# Uncaught errors and unhandled rejections reach us through the window's
|
|
143
|
+
# WHATWG report funnel, so the page's own `window.onerror` /
|
|
144
|
+
# `unhandledrejection` handlers get first refusal — only what it leaves
|
|
145
|
+
# unhandled is recorded, like a browser console. A document with no
|
|
146
|
+
# window (nothing to report to) records directly.
|
|
147
|
+
if window
|
|
148
|
+
window.__internal_on_unhandled_error__ { |err| record_js_error(err) }
|
|
149
|
+
# A rejection the page handled after we reported it is retracted, so it
|
|
150
|
+
# stops failing anything (WHATWG `rejectionhandled`).
|
|
151
|
+
window.__internal_on_rejection_handled__ { |record| @error_log.retract(record) }
|
|
152
|
+
rt.on_unhandled_rejection { |err| report_rejection(window, err) }
|
|
153
|
+
if rt.respond_to?(:on_callback_error)
|
|
154
|
+
rt.on_callback_error { |err| ::Dommy::Internal::ExceptionReport.report_at(window, err) }
|
|
155
|
+
end
|
|
156
|
+
else
|
|
157
|
+
rt.on_unhandled_rejection { |err| record_js_error(err) }
|
|
158
|
+
rt.on_callback_error { |err| record_js_error(err) } if rt.respond_to?(:on_callback_error)
|
|
159
|
+
end
|
|
131
160
|
rt.on_log { |log| record_console(log) }
|
|
132
161
|
rt.define_host_object("document", doc)
|
|
133
|
-
if
|
|
162
|
+
if window
|
|
134
163
|
rt.install_window(window)
|
|
135
164
|
rt.install_browser_globals
|
|
136
165
|
# Page-initiated navigations (JS location.href=, form submit, activated
|
|
@@ -182,10 +211,17 @@ module Dommy
|
|
|
182
211
|
@runtimes = {}.compare_by_identity
|
|
183
212
|
end
|
|
184
213
|
|
|
214
|
+
# Route an unhandled promise rejection through the page's own
|
|
215
|
+
# `unhandledrejection` handling first.
|
|
216
|
+
def report_rejection(window, error)
|
|
217
|
+
value = ::Dommy::Internal::ExceptionReport.error_value(error)
|
|
218
|
+
window.__internal_report_rejection__(value, host_error: error)
|
|
219
|
+
end
|
|
220
|
+
|
|
185
221
|
# Collect a JS error / console log into the cross-realm streams and fan it
|
|
186
222
|
# out to any registered observers (the Trace).
|
|
187
223
|
def record_js_error(err)
|
|
188
|
-
@
|
|
224
|
+
@error_log.record(err)
|
|
189
225
|
@js_error_listeners.each { |cb| cb.call(err) }
|
|
190
226
|
end
|
|
191
227
|
|
data/lib/dommy/rack/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dommy-rack
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.13.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- takahashim
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.
|
|
18
|
+
version: 0.13.0
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.
|
|
25
|
+
version: 0.13.0
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: rack
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|