Module: Isomorfeus::Puppetmaster::Driver::PuppeteerDocument
- Included in:
- Puppeteer
- Defined in:
- lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb
Instance Method Summary collapse
- #document_accept_alert(document, **options, &block) ⇒ Object
- #document_accept_confirm(document, **options, &block) ⇒ Object
- #document_accept_leave_page(document, **options, &block) ⇒ Object
- #document_accept_prompt(document, **options, &block) ⇒ Object
- #document_all_text(document) ⇒ Object
- #document_body(document) ⇒ Object
- #document_bring_to_front(document) ⇒ Object
- #document_clear_authentication_credentials(document) ⇒ Object
- #document_clear_cookies(document) ⇒ Object
- #document_clear_extra_headers(document) ⇒ Object
- #document_clear_url_blacklist(document) ⇒ Object
- #document_click(document, x: nil, y: nil, modifiers: nil) ⇒ Object
- #document_close(document) ⇒ Object
- #document_console(document) ⇒ Object
- #document_cookies(document) ⇒ Object
- #document_dismiss_confirm(document, **options, &block) ⇒ Object
- #document_dismiss_leave_page(document, **options, &block) ⇒ Object
- #document_dismiss_prompt(document, **options, &block) ⇒ Object
- #document_dispatch_event(document, name, event_type = nil, **options) ⇒ Object
- #document_double_click(document, x: nil, y: nil, modifiers: nil) ⇒ Object
- #document_evaluate_script(document, script, *args) ⇒ Object
- #document_execute_script(document, script, *args) ⇒ Object
- #document_find(document, selector) ⇒ Object
- #document_find_all(document, selector) ⇒ Object
- #document_find_all_xpath(document, query) ⇒ Object
- #document_find_xpath(document, query) ⇒ Object
- #document_go_back(document) ⇒ Object
- #document_go_forward(document) ⇒ Object
- #document_goto(document, uri) ⇒ Object
- #document_head(document) ⇒ Object
- #document_html(document) ⇒ Object
- #document_open_new_document(_document, uri = nil) ⇒ Object
- #document_reload(document) ⇒ Object
- #document_remove_cookie(document, name) ⇒ Object
- #document_render_base64(document, **options) ⇒ Object
- #document_reset_user_agent(document) ⇒ Object
- #document_right_click(document, x: nil, y: nil, modifiers: nil) ⇒ Object
- #document_save_pdf(document, path, **options) ⇒ Object
- #document_save_screenshot(document, path, **options) ⇒ Object
- #document_scroll_by(document, x, y) ⇒ Object
- #document_scroll_to(document, x, y) ⇒ Object
- #document_set_authentication_credentials(document, username, password) ⇒ Object
- #document_set_cookie(document, name, value, **options) ⇒ Object
- #document_set_extra_headers(document, headers_hash) ⇒ Object
- #document_set_url_blacklist(document, url_array) ⇒ Object
- #document_set_user_agent(document, agent_string) ⇒ Object
- #document_title(document) ⇒ Object
- #document_type_keys(document, *keys) ⇒ Object
- #document_url(document) ⇒ Object
- #document_user_agent(document) ⇒ Object
- #document_viewport_maximize(document) ⇒ Object
- #document_viewport_resize(document, width, height) ⇒ Object
- #document_viewport_size(document) ⇒ Object
- #document_wait_for(document, selector) ⇒ Object
- #document_wait_for_xpath(document, query) ⇒ Object
Instance Method Details
#document_accept_alert(document, **options, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 5 def document_accept_alert(document, **, &block) # TODO maybe wrap in mutex text = .has_key?(:text) ? "`#{options[:text]}`" : 'null' @context.exec " ModalText = \#{text};\n AllPageHandles[\#{document.handle}].on('dialog', DialogAcceptHandler);\n JAVASCRIPT\n block.call\n sleep @reaction_timeout\n @context.eval 'ModalText'\nensure\n matched = await <<~JAVASCRIPT\n LastResult = ModalTextMatched;\n ModalTextMatched = false;\n ModalText = null;\n AllPageHandles[\#{document.handle}].removeListener('dialog', DialogAcceptHandler);\n JAVASCRIPT\n raise Isomorfeus::Puppetmaster::NoModalError if options.has_key?(:text) && !matched\nend\n" |
#document_accept_confirm(document, **options, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 25 def document_accept_confirm(document, **, &block) # TODO maybe wrap in mutex text = .has_key?(:text) ? "`#{options[:text]}`" : 'null' @context.exec " ModalText = \#{text};\n AllPageHandles[\#{document.handle}].on('dialog', DialogAcceptHandler);\n JAVASCRIPT\n block.call\n sleep @reaction_timeout\n @context.eval 'ModalText'\nensure\n matched = await <<~JAVASCRIPT\n LastResult = ModalTextMatched;\n ModalTextMatched = false;\n ModalText = null;\n AllPageHandles[\#{document.handle}].removeListener('dialog', DialogAcceptHandler);\n JAVASCRIPT\n raise Isomorfeus::Puppetmaster::NoModalError if options.has_key?(:text) && !matched\nend\n" |
#document_accept_leave_page(document, **options, &block) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 45 def document_accept_leave_page(document, **, &block) # TODO maybe wrap in mutex text = .has_key?(:text) ? "`#{options[:text]}`" : 'null' @context.exec " ModalText = \#{text};\n AllPageHandles[\#{document.handle}].on('dialog', DialogAcceptHandler);\n JAVASCRIPT\n block.call\n sleep @reaction_timeout\n @context.eval 'ModalText'\nensure\n matched = await <<~JAVASCRIPT\n LastResult = ModalTextMatched;\n ModalTextMatched = false;\n ModalText = null;\n AllPageHandles[\#{document.handle}].removeListener('dialog', DialogAcceptHandler);\n JAVASCRIPT\n raise Isomorfeus::Puppetmaster::NoModalError if options.has_key?(:text) && !matched\nend\n" |
#document_accept_prompt(document, **options, &block) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 65 def document_accept_prompt(document, **, &block) # TODO maybe wrap in mutex text = .has_key?(:text) ? "`#{options[:text]}`" : 'null' @context.exec " ModalText = \#{text};\n AllPageHandles[\#{document.handle}].on('dialog', DialogAcceptHandler);\n JAVASCRIPT\n block.call\n sleep @reaction_timeout\n @context.eval 'ModalText'\nensure\n matched = await <<~JAVASCRIPT\n LastResult = ModalTextMatched;\n ModalTextMatched = false;\n ModalText = null;\n AllPageHandles[\#{document.handle}].removeListener('dialog', DialogAcceptHandler);\n JAVASCRIPT\n raise Isomorfeus::Puppetmaster::NoModalError if options.has_key?(:text) && !matched\nend\n" |
#document_all_text(document) ⇒ Object
85 86 87 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 85 def document_all_text(document) await("LastResult = AllPageHandles[#{document.handle}].evaluate(function(){ return document.documentElement.textContent; });") end |
#document_body(document) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 89 def document_body(document) node_data = await " var element_handle = await AllPageHandles[\#{document.handle}].$('body');\n if (element_handle) {\n var node_handle = RegisterElementHandle(element_handle);\n var tt = await AllElementHandles[node_handle].executionContext().evaluate((node) => {\n var name = node.nodeName;\n var tag = node.tagName.toLowerCase();\n return [name, tag, null, node.isContentEditable];\n }, AllElementHandles[node_handle]);\n LastResult = {handle: node_handle, name: tt[0], tag: tt[1], type: tt[2], content_editable: tt[3]};\n }\n JAVASCRIPT\n if node_data\n node_data[:css_selector] = 'body'\n Isomorfeus::Puppetmaster::Node.new_by_tag(self, document, node_data)\n end\nend\n" |
#document_bring_to_front(document) ⇒ Object
108 109 110 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 108 def document_bring_to_front(document) await("await AllPageHandles[#{document.handle}].bringToFront();") end |
#document_clear_authentication_credentials(document) ⇒ Object
112 113 114 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 112 def document_clear_authentication_credentials(document) await("AllPageHandles[#{document.handle}].authenticate(null);") end |
#document_clear_cookies(document) ⇒ Object
116 117 118 119 120 121 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 116 def (document) await " var cookies = await AllPageHandles[\#{document.handle}].cookies();\n cookies.forEach(async(cookie) => {await AllPageHandles[\#{document.handle}].deleteCookie(cookie);});\n JAVASCRIPT\nend\n" |
#document_clear_extra_headers(document) ⇒ Object
123 124 125 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 123 def document_clear_extra_headers(document) await ("AllPageHandles[#{document.handle}].setExtraHTTPHeaders({});") end |
#document_clear_url_blacklist(document) ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 127 def document_clear_url_blacklist(document) await " var cdp_session = await AllPageHandles[\#{document.handle}].target().createCDPSession();\n await cdp_session.send('Network.setBlockedURLs', {urls: []});\n await cdp_session.detach();\n JAVASCRIPT\nend\n" |
#document_click(document, x: nil, y: nil, modifiers: nil) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 135 def document_click(document, x: nil, y: nil, modifiers: nil) # modifier_keys: :alt, :control, :meta, :shift # await "await AllPageHandles[#{document.handle}].mouse.click(#{x},#{y},{button: 'left'});" # raise Isomorfeus::Pupppetmaster::InvalidActionError.new(:click) unless visible? modifiers = [modifiers] if modifiers.is_a?(Symbol) modifiers = [] unless modifiers modifiers = modifiers.map {|key| key.to_s.camelize(:lower) } await " var response_event_occurred = false;\n var response_handler = function(event){ response_event_occurred = true; };\n var response_watcher = new Promise(function(resolve, reject){\n setTimeout(function(){\n if (!response_event_occurred) { resolve(true); } \n else { setTimeout(function(){ resolve(true); }, \#{@puppeteer_timeout}); }\n AllPageHandles[\#{document.handle}].removeListener('response', response_handler);\n }, \#{@puppeteer_reaction_timeout});\n });\n AllPageHandles[\#{document.handle}].on('response', response_handler);\n var navigation_watcher = AllPageHandles[\#{document.handle}].waitForNavigation();\n await AllPageHandles[\#{document.handle}].evaluate(function(){ \n var options = {button: 0, bubbles: true, cancelable: true};\n var node = window;\n var x = \#{x ? x : 'null'};\n var y = \#{y ? y : 'null'};\n var modifiers = \#{modifiers};\n if (x && y) {\n options['clientX'] = x;\n options['clientY'] = y;\n var n = document.elementFromPoint(x, y);\n if (n) { node = n };\n } \n if (modifiers.includes('meta')) { options['metaKey'] = true; }\n if (modifiers.includes('control')) { options['ctrlKey'] = true; }\n if (modifiers.includes('shift')) { options['shiftKey'] = true; }\n if (modifiers.includes('alt')) { options['altKey'] = true; }\n node.dispatchEvent(new MouseEvent('mousedown', options));\n node.dispatchEvent(new MouseEvent('mouseup', options));\n node.dispatchEvent(new MouseEvent('click', options));\n });\n await Promise.race([response_watcher, navigation_watcher]);\n JAVASCRIPT\nend\n" |
#document_close(document) ⇒ Object
178 179 180 181 182 183 184 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 178 def document_close(document) await " await AllPageHandles[\#{document.handle}].close();\n delete AllPageHandles[\#{document.handle}];\n delete ConsoleMessages[\#{document.handle}];\n JAVASCRIPT\nend\n" |
#document_console(document) ⇒ Object
186 187 188 189 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 186 def document_console(document) = @context.exec "return ConsoleMessages[#{document.handle}]" .map {|m| Isomorfeus::Puppetmaster::ConsoleMessage.new(m)} end |
#document_cookies(document) ⇒ Object
191 192 193 194 195 196 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 191 def (document) result = await("LastResult = await AllPageHandles[#{document.handle}].cookies();") result_hash = {} result.each { || result_hash[['name']] = Isomorfeus::Puppetmaster::Cookie.new() } result_hash end |
#document_dismiss_confirm(document, **options, &block) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 198 def document_dismiss_confirm(document, **, &block) # TODO text = .has_key?(:text) ? "`#{options[:text]}`" : 'null' @context.exec " ModalText = \#{text};\n AllPageHandles[\#{document.handle}].on('dialog', DialogDismissHandler);\n JAVASCRIPT\n block.call\n sleep @reaction_timeout\n @context.eval 'ModalText'\nensure\n matched = await <<~JAVASCRIPT\n LastResult = ModalTextMatched;\n ModalTextMatched = false;\n ModalText = null;\n AllPageHandles[\#{document.handle}].removeListener('dialog', DialogDismissHandler);\n JAVASCRIPT\n raise Isomorfeus::Puppetmaster::ModalNotFound if options.has_key?(:text) && !matched\nend\n" |
#document_dismiss_leave_page(document, **options, &block) ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 218 def document_dismiss_leave_page(document, **, &block) # TODO text = .has_key?(:text) ? "`#{options[:text]}`" : 'null' @context.exec " ModalText = \#{text};\n AllPageHandles[\#{document.handle}].on('dialog', DialogDismissHandler);\n JAVASCRIPT\n block.call\n sleep @reaction_timeout\n @context.eval 'ModalText'\nensure\n matched = await <<~JAVASCRIPT\n LastResult = ModalTextMatched;\n ModalTextMatched = false;\n ModalText = null;\n AllPageHandles[\#{document.handle}].removeListener('dialog', DialogDismissHandler);\n JAVASCRIPT\n raise Isomorfeus::Puppetmaster::ModalNotFound if options.has_key?(:text) && !matched\nend\n" |
#document_dismiss_prompt(document, **options, &block) ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 238 def document_dismiss_prompt(document, **, &block) # TODO text = .has_key?(:text) ? "`#{options[:text]}`" : 'null' @context.exec " ModalText = \#{text};\n AllPageHandles[\#{document.handle}].on('dialog', DialogDismissHandler);\n JAVASCRIPT\n block.call\n sleep @reaction_timeout\n @context.eval 'ModalText'\nensure\n matched = await <<~JAVASCRIPT\n LastResult = ModalTextMatched;\n ModalTextMatched = false;\n ModalText = null;\n AllPageHandles[\#{document.handle}].removeListener('dialog', DialogDismissHandler);\n JAVASCRIPT\n raise Isomorfeus::Puppetmaster::ModalNotFound if options.has_key?(:text) && !matched\nend\n" |
#document_dispatch_event(document, name, event_type = nil, **options) ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 258 def document_dispatch_event(document, name, event_type = nil, **) raise ArgumentError, 'Unknown event' unless EVENTS.key?(name.to_sym) || event_type event_type, opts = *EVENTS[name.to_s.downcase.tr('_', '').to_sym] if event_type.nil? opts.merge!() await " handle = await AllPageHandles[\#{document.handle}].evaluate(function(node){\n var event = new \#{event_type}('\#{name}'\#{opts.empty? ? '' : opts});\n document.dispatchEvent(event);\n });\n JAVASCRIPT\nend\n" |
#document_double_click(document, x: nil, y: nil, modifiers: nil) ⇒ Object
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 270 def document_double_click(document, x: nil, y: nil, modifiers: nil) # modifier_keys: :alt, :control, :meta, :shift modifiers = [modifiers] if modifiers.is_a?(Symbol) modifiers = [] unless modifiers modifiers = modifiers.map {|key| key.to_s.camelize(:lower) } await " var response_event_occurred = false;\n var response_handler = function(event){ response_event_occurred = true; };\n var response_watcher = new Promise(function(resolve, reject){\n setTimeout(function(){\n if (!response_event_occurred) { resolve(true); } \n else { setTimeout(function(){ resolve(true); }, \#{@puppeteer_timeout}); }\n AllPageHandles[\#{document.handle}].removeListener('response', response_handler);\n }, \#{@puppeteer_reaction_timeout});\n });\n AllPageHandlers[\#{document.handle}].on('response', response_handler);\n var navigation_watcher = AllPageHandles[\#{document.handle}].waitForNavigation();\n await AllPageHandles[\#{document.handle}].evaluate(function(){\n var options = {button: 0, bubbles: true, cancelable: true};\n var node = window;\n var x = \#{x ? x : 'null'};\n var y = \#{y ? y : 'null'};\n var modifiers = \#{modifiers};\n if (x && y) {\n options['clientX'] = x;\n options['clientY'] = y;\n var n = document.elementFromPoint(x, y);\n if (n) { node = n };\n }\n if (modifiers.includes('meta')) { options['metaKey'] = true; }\n if (modifiers.includes('control')) { options['ctrlKey'] = true; }\n if (modifiers.includes('shift')) { options['shiftKey'] = true; }\n if (modifiers.includes('alt')) { options['altKey'] = true; }\n node.dispatchEvent(new MouseEvent('mousedown', options));\n node.dispatchEvent(new MouseEvent('mouseup', options));\n node.dispatchEvent(new MouseEvent('dblclick', options));\n });\n await Promise.race([response_watcher, navigation_watcher]);\n JAVASCRIPT\nend\n" |
#document_evaluate_script(document, script, *args) ⇒ Object
311 312 313 314 315 316 317 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 311 def document_evaluate_script(document, script, *args) await " LastResult = await AllPageHandles[\#{document.handle}].evaluate((arguments) => {\n return \#{script.strip} \n }, \#{args});\n JAVASCRIPT\nend\n" |
#document_execute_script(document, script, *args) ⇒ Object
319 320 321 322 323 324 325 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 319 def document_execute_script(document, script, *args) await " LastResult = await AllPageHandles[\#{document.handle}].evaluate((arguments) => {\n \#{script.strip} \n }, \#{args});\n JAVASCRIPT\nend\n" |
#document_find(document, selector) ⇒ Object
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 327 def document_find(document, selector) js_escaped_selector = selector.gsub('\\', '\\\\\\').gsub('"', '\"') node_data = await " var element_handle = await AllPageHandles[\#{document.handle}].$(\"\#{js_escaped_selector}\");\n if (element_handle) {\n var node_handle = RegisterElementHandle(element_handle);\n var tt = await AllPageHandles[\#{document.handle}].evaluate((node) => {\n var tag = node.tagName ? node.tagName.toLowerCase() : '';\n var name = node.nodeName;\n var type = null;\n if (tag === 'input') { type = node.getAttribute('type'); }\n return [name, tag, type, node.isContentEditable];\n }, AllElementHandles[node_handle]);\n LastResult = {handle: node_handle, name: tt[0], tag: tt[1], type: tt[2], content_editable: tt[3]};\n }\n JAVASCRIPT\n if node_data\n node_data[:css_selector] = selector\n Isomorfeus::Puppetmaster::Node.new_by_tag(self, document, node_data)\n else\n raise Isomorfeus::Puppetmaster::ElementNotFound.new(selector)\n end\nend\n" |
#document_find_all(document, selector) ⇒ Object
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 351 def document_find_all(document, selector) js_escaped_selector = selector.gsub('\\', '\\\\\\').gsub('"', '\"') node_data_array = await " var node_data_array = [];\n var element_handle_array = await AllPageHandles[\#{document.handle}].$$(\"\#{js_escaped_selector}\");\n if (element_handle_array) {\n for (var i=0; i<element_handle_array.length; i++) {\n var node_handle = RegisterElementHandle(element_handle_array[i]);\n var tt = await AllPageHandles[\#{document.handle}].evaluate((node) => {\n var tag = node.tagName ? node.tagName.toLowerCase() : '';\n var name = node.nodeName;\n var type = null;\n if (tag === 'input') { type = node.getAttribute('type'); }\n return [name, tag, type, node.isContentEditable];\n }, AllElementHandles[node_handle]);\n node_data_array.push({handle: node_handle, name: tt[0], tag: tt[1], type: tt[2], content_editable: tt[3]});\n } \n }\n LastResult = node_data_array;\n JAVASCRIPT\n node_data_array.map do |node_data|\n node_data[:css_selector] = selector\n Isomorfeus::Puppetmaster::Node.new_by_tag(self, document, node_data)\n end\nend\n" |
#document_find_all_xpath(document, query) ⇒ Object
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 377 def document_find_all_xpath(document, query) js_escaped_query = query.gsub('\\', '\\\\\\').gsub('"', '\"') node_data_array = await " var node_data_array = [];\n var element_handle_array = await AllPageHandles[\#{document.handle}].$x(\"\#{js_escaped_query}\");\n if (element_handle_array) { \n for (var i=0; i<element_handle_array.length; i++) {\n var node_handle = RegisterElementHandle(element_handle_array[i]);\n var tt = await AllPageHandles[\#{document.handle}].evaluate((node) => {\n var tag = node.tagName ? node.tagName.toLowerCase() : '';\n var name = node.nodeName;\n var type = null;\n if (tag === 'input') { type = node.getAttribute('type'); }\n return [name, tag, type, node.isContentEditable];\n }, AllElementHandles[node_handle]);\n node_data_array.push({handle: node_handle, name: tt[0], tag: tt[1], type: tt[2], content_editable: tt[3]});\n }\n }\n LastResult = node_data_array;\n JAVASCRIPT\n node_data_array.map do |node_data|\n node_data[:xpath_query] = query\n Isomorfeus::Puppetmaster::Node.new_by_tag(self, document, node_data)\n end\nend\n" |
#document_find_xpath(document, query) ⇒ Object
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 403 def document_find_xpath(document, query) js_escaped_query = query.gsub('\\', '\\\\\\').gsub('"', '\"') node_data = await " var element_handle_array = await AllPageHandles[\#{document.handle}].$x(\"\#{js_escaped_query}\");\n var element_handle = (element_handle_array) ? element_handle_array[0] : null;\n if (element_handle) {\n var node_handle = RegisterElementHandle(element_handle);\n var tt = await AllPageHandles[\#{document.handle}].evaluate((node) => {\n var tag = node.tagName ? node.tagName.toLowerCase() : '';\n var name = node.nodeName;\n var type = null;\n if (tag === 'input') { type = node.getAttribute('type'); }\n return [name, tag, type, node.isContentEditable];\n }, AllElementHandles[node_handle]);\n LastResult = {handle: node_handle, name: tt[0], tag: tt[1], type: tt[2], content_editable: tt[3]};\n }\n JAVASCRIPT\n if node_data\n node_data[:xpath_query] = query\n Isomorfeus::Puppetmaster::Node.new_by_tag(self, document, node_data)\n else\n raise Isomorfeus::Puppetmaster::ElementNotFound.new(query)\n end\nend\n" |
#document_go_back(document) ⇒ Object
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 428 def document_go_back(document) response_hash, = await " ConsoleMessages[\#{document.handle}] = [];\n var response = await AllPageHandles[\#{document.handle}].goBack();\n if (response) {\n var request = response.request();\n var formatted_response = {\n headers: response.headers(),\n ok: response.ok(),\n remote_address: response.remoteAddress(),\n request: {\n failure: request.failure(),\n headers: request.headers(),\n method: request.method(),\n post_data: request.postData(),\n resource_type: request.resourceType(),\n url: request.url()\n },\n status: response.status(),\n status_text: response.statusText(),\n text: response.text(),\n url: response.url()\n };\n LastResult = [formatted_response, ConsoleMessages[\#{document.handle}]];\n } else {\n LastResult = [null, ConsoleMessages[\#{document.handle}]];\n }\n JAVASCRIPT\n con_messages = messages.map {|m| Isomorfeus::Puppetmaster::ConsoleMessage.new(m)}\n con_messages.each { |m| raise determine_error(m.text) if m.level == 'error' && !m.text.start_with?('Failed to load resource:') }\n if response_hash\n response = Isomorfeus::Puppetmaster::Response.new(response_hash)\n document.instance_variable_set(:@response, response)\n end\n document.response\nend\n" |
#document_go_forward(document) ⇒ Object
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 465 def document_go_forward(document) response_hash, = await " ConsoleMessages[\#{document.handle}] = [];\n var response = await AllPageHandles[\#{document.handle}].goForward();\n if (response) {\n var request = response.request();\n var formatted_response = {\n headers: response.headers(),\n ok: response.ok(),\n remote_address: response.remoteAddress(),\n request: {\n failure: request.failure(),\n headers: request.headers(),\n method: request.method(),\n post_data: request.postData(),\n resource_type: request.resourceType(),\n url: request.url()\n },\n status: response.status(),\n status_text: response.statusText(),\n text: response.text(),\n url: response.url()\n };\n LastResult = [formatted_response, ConsoleMessages[\#{document.handle}]];\n } else {\n LastResult = [null, ConsoleMessages[\#{document.handle}]];\n }\n JAVASCRIPT\n con_messages = messages.map {|m| Isomorfeus::Puppetmaster::ConsoleMessage.new(m)}\n con_messages.each { |m| raise determine_error(m.text) if m.level == 'error' && !m.text.start_with?('Failed to load resource:') }\n if response_hash\n response = Isomorfeus::Puppetmaster::Response.new(response_hash)\n document.instance_variable_set(:@response, response)\n end\n document.response\nend\n" |
#document_goto(document, uri) ⇒ Object
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 502 def document_goto(document, uri) parsed_uri = URI.parse(uri) parsed_uri.host = @app.host unless parsed_uri.host parsed_uri.port = @app.port unless parsed_uri.port parsed_uri.scheme = @app.scheme unless parsed_uri.scheme response_hash, = await " ConsoleMessages[\#{document.handle}] = [];\n var response = await AllPageHandles[\#{document.handle}].goto('\#{parsed_uri.to_s}');\n if (response) {\n var request = response.request();\n var formatted_response = {\n headers: response.headers(),\n ok: response.ok(),\n remote_address: response.remoteAddress(),\n request: {\n failure: request.failure(),\n headers: request.headers(),\n method: request.method(),\n post_data: request.postData(),\n resource_type: request.resourceType(),\n url: request.url()\n },\n status: response.status(),\n status_text: response.statusText(),\n text: response.text(),\n url: response.url()\n };\n LastResult = [formatted_response, ConsoleMessages[\#{document.handle}]];\n } else {\n LastResult = [null, ConsoleMessages[\#{document.handle}]];\n }\n JAVASCRIPT\n con_messages = messages.map {|m| Isomorfeus::Puppetmaster::ConsoleMessage.new(m)}\n con_messages.each { |m| raise determine_error(m.text) if m.level == 'error' && !m.text.start_with?('Failed to load resource:') }\n if response_hash\n response = Isomorfeus::Puppetmaster::Response.new(response_hash)\n document.instance_variable_set(:@response, response)\n end\n document.response\nend\n" |
#document_head(document) ⇒ Object
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 543 def document_head(document) node_data = await " var element_handle = await AllPageHandles[\#{document.handle}].$('head');\n if (element_handle) {\n var node_handle = RegisterElementHandle(element_handle);\n var tt = await AllElementHandles[node_handle].executionContext().evaluate((node) => {\n var name = node.nodeName;\n var tag = node.tagName.toLower();\n return [name, tag, null, node.isContentEditable];\n }, AllElementHandles[node_handle]);\n LastResult = {handle: node_handle, name: tt[0], tag: tt[1], type: tt[2], content_editable: tt[3]};\n }\n JAVASCRIPT\n if node_data\n node_data[:css_selector] = selector\n Isomorfeus::Puppetmaster::Node.new_by_tag(self, document, node_data)\n end\nend\n" |
#document_html(document) ⇒ Object
562 563 564 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 562 def document_html(document) await "LastResult = await AllPageHandles[#{document.handle}].content();" end |
#document_open_new_document(_document, uri = nil) ⇒ Object
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 566 def document_open_new_document(_document, uri = nil) if !uri || uri == 'about:blank' parsed_uri = 'about:blank' else parsed_uri = URI.parse(uri) parsed_uri.host = @app.host unless parsed_uri.host parsed_uri.port = @app.port unless parsed_uri.port parsed_uri.scheme = @app.scheme unless parsed_uri.scheme end handle, response_hash, = await " var new_page = await CurrentBrowser.newPage();\n var url = '\#{parsed_uri.to_s}';\n new_page.setDefaultTimeout(\#{@puppeteer_timeout});\n await new_page.setViewport({width: \#{@width}, height: \#{@height}});\n var new_target = new_page.target();\n var cdp_session = await new_target.createCDPSession();\n await cdp_session.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: '\#{Isomorfeus::Puppetmaster.download_path}'});\n if (\#{@url_blacklist}.length > 0) { await cdp_session.send('Network.setBlockedURLs', {urls: \#{@url_blacklist}}); }\n await cdp_session.detach();\n var page_handle = RegisterPage(new_page); \n var result_response = null;\n if (url && url !== '') { \n var response = await new_page.goto(url);\n if (response) {\n var request = response.request();\n result_response = {\n headers: response.headers(),\n ok: response.ok(),\n remote_address: response.remoteAddress(),\n request: {\n failure: request.failure(),\n headers: request.headers(),\n method: request.method(),\n post_data: request.postData(),\n resource_type: request.resourceType(),\n url: request.url()\n },\n status: response.status(),\n status_text: response.statusText(),\n text: response.text(),\n url: response.url()\n } \n }\n };\n LastResult = [page_handle, result_response, ConsoleMessages[page_handle]];\n JAVASCRIPT\n con_messages = messages.map {|m| Isomorfeus::Puppetmaster::ConsoleMessage.new(m)}\n con_messages.each { |m| raise determine_error(m.text) if m.level == 'error' && !m.text.start_with?('Failed to load resource:') }\n Isomorfeus::Puppetmaster::Document.new(self, handle, Isomorfeus::Puppetmaster::Response.new(response_hash))\nend\n" |
#document_reload(document) ⇒ Object
617 618 619 620 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 617 def document_reload(document) response_hash = await"LastResult = await AllPageHandles[#{document.handle}].reload();" Isomorfeus::Puppetmaster::Response.new(response_hash) end |
#document_remove_cookie(document, name) ⇒ Object
622 623 624 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 622 def (document, name) await "await AllPageHandles[#{document.handle}].deleteCookie({name: '#{name}'})" end |
#document_render_base64(document, **options) ⇒ Object
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 626 def document_render_base64(document, **) # todo # https://pptr.dev/#?product=Puppeteer&version=v1.12.2&show=api-pagescreenshotoptions = ["encoding: 'base64'"] if .has_key?(:format) [:format] = 'jpeg' if [:format].to_s.downcase == 'jpg' << "type: '#{options.delete(:format).to_s.downcase}'" end << "quality: #{options.delete(:quality)}" if .has_key?(:quality) << "fullPage: #{options.delete(:full)}" if .has_key?(:full) .each do |k,v| << "#{k.to_s.camelize(:lower)}: #{v}" end await "LastResult = await AllPageHandles[#{document.handle}].screenshot({#{final_options.join(', ')}});" end |
#document_reset_user_agent(document) ⇒ Object
642 643 644 645 646 647 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 642 def document_reset_user_agent(document) await " var original_user_agent = await CurrentBrowser.userAgent();\n await AllPageHandles[\#{document.handle}].setUserAgent(original_user_agent);\n JAVASCRIPT\nend\n" |
#document_right_click(document, x: nil, y: nil, modifiers: nil) ⇒ Object
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 649 def document_right_click(document, x: nil, y: nil, modifiers: nil) # modifier_keys: :alt, :control, :meta, :shift # offset: { x: int, y: int } modifiers = [modifiers] if modifiers.is_a?(Symbol) modifiers = [] unless modifiers modifiers = modifiers.map {|key| key.to_s.camelize(:lower) } await " var response_event_occurred = false;\n var response_handler = function(event){ response_event_occurred = true; };\n var response_watcher = new Promise(function(resolve, reject){\n setTimeout(function(){\n if (!response_event_occurred) { resolve(true); } \n else { setTimeout(function(){ resolve(true); }, \#{@puppeteer_timeout}); }\n AllPageHandles[\#{document.handle}].removeListener('response', response_handler);\n }, \#{@puppeteer_reaction_timeout});\n });\n AllPageHandles[\#{document.handle}].on('response', response_handler);\n var navigation_watcher = AllPageHandles[\#{document.handle}].waitForNavigation();\n await AllPageHandles[\#{document.handle}].evaluate(function(){\n var options = {button: 2, bubbles: true, cancelable: true};\n var node = window;\n var x = \#{x ? x : 'null'};\n var y = \#{y ? y : 'null'};\n var modifiers = \#{modifiers};\n if (x && y) {\n options['clientX'] = x;\n options['clientY'] = y;\n var n = document.elementFromPoint(x, y);\n if (n) { node = n };\n }\n if (modifiers.includes('meta')) { options['metaKey'] = true; }\n if (modifiers.includes('control')) { options['ctrlKey'] = true; }\n if (modifiers.includes('shift')) { options['shiftKey'] = true; }\n if (modifiers.includes('alt')) { options['altKey'] = true; }\n node.dispatchEvent(new MouseEvent('mousedown', options));\n node.dispatchEvent(new MouseEvent('mouseup', options));\n node.dispatchEvent(new MouseEvent('contextmenu', options));\n });\n await Promise.race([response_watcher, navigation_watcher]);\n JAVASCRIPT\nend\n" |
#document_save_pdf(document, path, **options) ⇒ Object
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 691 def document_save_pdf(document, path, **) # todo # https://pptr.dev/#?product=Puppeteer&version=v1.12.2&show=api-pagepdfoptions absolute_path = File.absolute_path(path) = ["path: '#{absolute_path}'"] << "format: '#{options.delete(:format)}'" if .has_key?(:format) << "headerTemplate: `#{options.delete(:header_template)}`" if .has_key?(:header_template) << "footerTemplate: `#{options.delete(:footer_template)}`" if .has_key?(:footer_template) << "pageRanges: '#{options.delete(:page_ranges)}'" if .has_key?(:page_ranges) << "width: '#{options.delete(:width)}'" if .has_key?(:width) << "height: '#{options.delete(:height)}'" if .has_key?(:height) .each do |k,v| << "#{k.to_s.camelize(:lower)}: #{v}" end await "await AllPageHandles[#{document.handle}].pdf({#{final_options.join(', ')}});" end |
#document_save_screenshot(document, path, **options) ⇒ Object
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 708 def document_save_screenshot(document, path, **) # todo # https://pptr.dev/#?product=Puppeteer&version=v1.12.2&show=api-pagescreenshotoptions absolute_path = File.absolute_path(path) = ["path: '#{absolute_path}'"] if .has_key?(:format) [:format] = 'jpeg' if [:format].to_s.downcase == 'jpg' << "type: '#{options.delete(:format).to_s.downcase}'" end << "quality: #{options.delete(:quality)}" if .has_key?(:quality) << "fullPage: #{options.delete(:full)}" if .has_key?(:full) .each do |k,v| << "#{k.to_s.camelize(:lower)}: #{v}" end await "await AllPageHandles[#{document.handle}].screenshot({#{final_options.join(', ')}});" end |
#document_scroll_by(document, x, y) ⇒ Object
725 726 727 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 725 def document_scroll_by(document, x, y) await "await AllPageHandles[#{document.handle}].evaluate('window.scrollBy(#{x}, #{y})');" end |
#document_scroll_to(document, x, y) ⇒ Object
729 730 731 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 729 def document_scroll_to(document, x, y) await "await AllPageHandles[#{document.handle}].evaluate('window.scrollTo(#{x}, #{y})');" end |
#document_set_authentication_credentials(document, username, password) ⇒ Object
733 734 735 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 733 def document_set_authentication_credentials(document, username, password) await "await AllPageHandles[#{document.handle}].authenticate({username: '#{username}', password: '#{password}'});" end |
#document_set_cookie(document, name, value, **options) ⇒ Object
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 737 def (document, name, value, **) [:name] ||= name [:value] ||= value uri = document_url(document) if uri == 'about:blank' uri = if Isomorfeus::Puppetmaster.server_host u = URI.new u.scheme = Isomorfeus::Puppetmaster.server_scheme if Isomorfeus::Puppetmaster.server_scheme u.host = Isomorfeus::Puppetmaster.server_host u.to_s else 'http://127.0.0.1' end end [:domain] ||= URI.parse(uri).host = [] << "expires: #{options.delete(:expires).to_i}" if .has_key?(:expires) << "httpOnly: #{options.delete(:http_only)}" if .has_key?(:http_only) << "secure: #{options.delete(:secure)}" if .has_key?(:secure) << "sameSite: '#{options.delete(:same_site)}'" if .has_key?(:same_site) .each do |k,v| << "#{k}: '#{v}'" end await "await AllPageHandles[#{document.handle}].setCookie({#{final_options.join(', ')}});" end |
#document_set_extra_headers(document, headers_hash) ⇒ Object
763 764 765 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 763 def document_set_extra_headers(document, headers_hash) await "await AllPageHandles[#{document.handle}].setExtraHTTPHeaders(#{Oj.dump(headers_hash, mode: :strict)});" end |
#document_set_url_blacklist(document, url_array) ⇒ Object
767 768 769 770 771 772 773 774 775 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 767 def document_set_url_blacklist(document, url_array) # https://www.chromium.org/administrators/url-blacklist-filter-format @url_blacklist = url_array await " var cdp_session = await AllPageHandles[\#{document.handle}].target().createCDPSession();\n await cdp_session.send('Network.setBlockedURLs', {urls: \#{url_array}});\n await cdp_session.detach();\n JAVASCRIPT\nend\n" |
#document_set_user_agent(document, agent_string) ⇒ Object
777 778 779 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 777 def document_set_user_agent(document, agent_string) await "await AllPageHandles[#{document.handle}].setUserAgent('#{agent_string}');" end |
#document_title(document) ⇒ Object
781 782 783 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 781 def document_title(document) await "LastResult = await AllPageHandles[#{document.handle}].title();" end |
#document_type_keys(document, *keys) ⇒ Object
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 785 def document_type_keys(document, *keys) cjs = "await AllPageHandles[#{document.handle}].bringToFront();" top_modifiers = [] keys.each do |key| if key.is_a?(String) key.each_char do |c| need_shift = /[[:upper:]]/.match(c) cjs << "await AllPageHandles[#{document.handle}].keyboard.down('Shift');\n" if need_shift c = "Key#{c.upcase}" if /[[:alpha:]]/.match(c) cjs << "await AllPageHandles[#{document.handle}].keyboard.down('#{c}');\n" cjs << "await AllPageHandles[#{document.handle}].keyboard.up('#{c}');\n" cjs << "await AllPageHandles[#{document.handle}].keyboard.up('Shift');\n" if need_shift end elsif key.is_a?(Symbol) if i[ctrl Ctrl].include?(key) key = :control elsif i[command Command Meta].include?(key) key = :meta elsif i[divide Divide].include?(key) key = :numpad_divide elsif i[decimal Decimal].include?(key) key = :numpad_decimal elsif i[left right up down].include?(key) key = "arrow_#{key}".to_sym end if i[alt alt_left alt_right control control_left control_rigth shift shift_left shift_right].include?(key) top_modifiers << key cjs << "await AllPageHandles[#{document.handle}].keyboard.down('#{key.to_s.camelize}');\n" else cjs << "await AllPageHandles[#{document.handle}].keyboard.press('#{key.to_s.camelize}');\n" end elsif key.is_a?(Array) modifiers = [] key.each do |k| if k.is_a?(Symbol) if i[ctrl Ctrl].include?(k) k = :control elsif i[command Command Meta].include?(k) k = :meta elsif i[divide Divide].include?(k) k = :numpad_divide elsif i[decimal Decimal].include?(k) k = :numpad_decimal elsif i[left right up down].include?(key) k = "arrow_#{key}".to_sym end if i[alt alt_left alt_right control control_left control_rigth shift shift_left shift_right].include?(k) modifiers << k cjs << "await AllPageHandles[#{document.handle}].keyboard.down('#{k.to_s.camelize}');\n" else cjs << "await AllPageHandles[#{document.handle}].keyboard.press('#{k.to_s.camelize}');\n" end elsif k.is_a?(String) k.each_char do |c| need_shift = /[[:upper:]]/.match(c) cjs << "await AllPageHandles[#{document.handle}].keyboard.down('Shift');\n" if need_shift c = "Key#{c.upcase}" if /[[:alpha:]]/.match(c) cjs << "await AllPageHandles[#{document.handle}].keyboard.press('#{c}');\n" cjs << "await AllPageHandles[#{document.handle}].keyboard.up('Shift');\n" if need_shift end end end modifiers.reverse.each do |k| cjs << "await AllPageHandles[#{document.handle}].keyboard.up('#{k.to_s.camelize}');\n" end end end top_modifiers.reverse.each do |key| cjs << "await AllPageHandles[#{document.handle}].keyboard.up('#{key.to_s.camelize}');\n" end await(cjs) end |
#document_url(document) ⇒ Object
858 859 860 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 858 def document_url(document) await "LastResult = await AllPageHandles[#{document.handle}].evaluate('window.location.href');" end |
#document_user_agent(document) ⇒ Object
862 863 864 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 862 def document_user_agent(document) await "LastResult = await AllPageHandles[#{document.handle}].evaluate('window.navigator.userAgent');" end |
#document_viewport_maximize(document) ⇒ Object
866 867 868 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 866 def (document) (document, @max_width, @max_height) end |
#document_viewport_resize(document, width, height) ⇒ Object
870 871 872 873 874 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 870 def (document, width, height) width = @max_width if width > @max_width height = @max_height if width > @max_height await "await AllPageHandles[#{document.handle}].setViewport({width: #{width}, height: #{height}});" end |
#document_viewport_size(document) ⇒ Object
876 877 878 879 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 876 def (document) = @context.eval "AllPageHandles[#{document.handle}].viewport()" [['width'], ['height']] end |
#document_wait_for(document, selector) ⇒ Object
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 881 def document_wait_for(document, selector) js_escaped_selector = selector.gsub('\\', '\\\\\\').gsub('"', '\"') node_data = await " var element_handle = await AllPageHandles[\#{document.handle}].waitForSelector(\"\#{js_escaped_selector}\");\n if (element_handle) {\n var node_handle = RegisterElementHandle(element_handle);\n var tt = await AllElementHandles[node_handle].executionContext().evaluate((node) => {\n var name = node.nodeName;\n var tag = node.tagName.toLowerCase();\n var type = null;\n if (tag === 'input') { type = node.getAttribute('type'); }\n return [name, tag, type, node.isContentEditable];\n }, AllElementHandles[node_handle]);\n LastResult = {handle: node_handle, name: tt[0], tag: tt[1], type: tt[2], content_editable: tt[3]};\n }\n JAVASCRIPT\n if node_data\n node_data[:css_selector] = selector\n Isomorfeus::Puppetmaster::Node.new_by_tag(self, document, node_data)\n else\n raise Isomorfeus::Puppetmaster::ElementNotFound.new(selector)\n end\nend\n" |
#document_wait_for_xpath(document, query) ⇒ Object
905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 |
# File 'lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb', line 905 def document_wait_for_xpath(document, query) js_escaped_query = query.gsub('\\', '\\\\\\').gsub('"', '\"') node_data = await " var element_handle = await AllPageHandles[\#{document.handle}].waitForXPath(\"\#{js_escaped_query}\");\n if (element_handle) {\n var node_handle = RegisterElementHandle(element_handle);\n var tt = await AllElementHandles[node_handle].executionContext().evaluate((node) => {\n var name = node.nodeName;\n var tag = node.tagName.toLowerCase();\n var type = null;\n if (tag === 'input') { type = node.getAttribute('type'); }\n return [name, tag, type, node.isContentEditable];\n }, AllElementHandles[node_handle]);\n LastResult = {handle: node_handle, name: tt[0], tag: tt[1], type: tt[2], content_editable: tt[3]};\n }\n JAVASCRIPT\n if node_data\n node_data[:xpath_query] = query\n Isomorfeus::Puppetmaster::Node.new_by_tag(self, document, node_data)\n else\n raise Isomorfeus::Puppetmaster::ElementNotFound.new(selector)\n end\nend\n" |