Module: Obxcura::Frame::DOM
- Included in:
- Obxcura::Frame
- Defined in:
- lib/obxcura/frame/dom.rb
Overview
DOM: high-level reads of the rendered page, all built on Runtime.
Selector queries return live Nodes. Obscura serializes a DOM node over
returnByValue as an internal stub carrying an _nid — useless on its own,
but the _nid resolves (DOM.resolveNode) to a real remote object handle we
wrap in a Node and drive with Runtime#call_on.
Instance Method Summary collapse
-
#at_css(selector) ⇒ Obxcura::Node?
First element matching a CSS selector.
-
#body ⇒ String
(also: #html)
The live, post-JS HTML, in a single round trip.
-
#css(selector) ⇒ Array<Obxcura::Node>
All elements matching a CSS selector.
-
#current_url ⇒ String
The current top-window URL.
-
#title ⇒ String
The current document title.
-
#to_node(stub) ⇒ Obxcura::Node?
Resolve Obscura's serialized node stub ("_nid"=>N,...) into a Node.
Instance Method Details
#at_css(selector) ⇒ Obxcura::Node?
First element matching a CSS selector.
35 36 37 |
# File 'lib/obxcura/frame/dom.rb', line 35 def at_css(selector) to_node(evaluate_func("function(s) { return document.querySelector(s); }", selector)) end |
#body ⇒ String Also known as: html
The live, post-JS HTML, in a single round trip. Obscura's frame ceiling is
64 MiB, so even a very large document comes back whole. Aliased as html.
26 27 28 |
# File 'lib/obxcura/frame/dom.rb', line 26 def body evaluate("document.documentElement.outerHTML") end |
#css(selector) ⇒ Array<Obxcura::Node>
All elements matching a CSS selector.
43 44 45 46 |
# File 'lib/obxcura/frame/dom.rb', line 43 def css(selector) Array(evaluate_func("function(s) { return Array.from(document.querySelectorAll(s)); }", selector)) .filter_map { |stub| to_node(stub) } end |
#current_url ⇒ String
Returns the current top-window URL.
13 14 15 |
# File 'lib/obxcura/frame/dom.rb', line 13 def current_url evaluate("window.location.href") end |
#title ⇒ String
Returns the current document title.
18 19 20 |
# File 'lib/obxcura/frame/dom.rb', line 18 def title evaluate("document.title") end |
#to_node(stub) ⇒ Obxcura::Node?
Resolve Obscura's serialized node stub ("_nid"=>N,...) into a Node. Public so Node#at_css can reuse the same resolution path.
53 54 55 56 57 58 59 |
# File 'lib/obxcura/frame/dom.rb', line 53 def to_node(stub) return nil unless stub.is_a?(Hash) && stub["_nid"] object_id = command("DOM.resolveNode", { nodeId: stub["_nid"] }).dig("object", "objectId") Node.new(self, object_id) end |