Class: Dhalang::Puppeteer

Inherits:
Object
  • Object
show all
Defined in:
lib/Dhalang/puppeteer.rb

Overview

Contains common logic for interacting with Puppeteer.

Class Method Summary collapse

Class Method Details

.visit(page_url, script_path, temp_file_path, temp_file_extension, options) ⇒ Object

Launches a new Node process, executing the (Puppeteer) script under the given script_path.

Parameters:

  • page_url (String)

    The url to pass to the goTo method of Puppeteer.

  • script_path (String)

    The absolute path of the JS script to execute.

  • temp_file_path (String)

    The absolute path of the temp file to use to write any actions from Puppeteer.

  • temp_file_extension (String)

    The extension of the temp file.

  • options (Object)

    Set of options to use, configurable by the user.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/Dhalang/puppeteer.rb', line 61

def self.visit(page_url, script_path, temp_file_path, temp_file_extension, options)
    configuration = create_configuration(page_url, script_path, temp_file_path, temp_file_extension, options)

    command = "node #{script_path} #{Shellwords.escape(configuration)}"

    Open3.popen2e(command) do |_stdin, stdouterr, wait|
        return nil if wait.value.success?

        output = stdouterr.read.strip
        output = nil if output == ''
        message = output || "Exited with status #{wait.value.exitstatus}"
        raise DhalangError, message
    end
end