Sha256: 8880249160475018fc9e20a5d07ac4fdd41cc98eef2df32ed0f57754290c21e4

Contents?: true

Size: 943 Bytes

Versions: 3

Compression:

Stored size: 943 Bytes

Contents

module Perus::Pinger
    class ChromeExecute < ChromeCommand
        description 'Executes JavaScript in the top Chrome window. The result
                     of the execution is stored and sent to the server.'
        option :js

        def run
            result = false
            command = '{"id":1,"method":"Runtime.evaluate","params":{"expression":"' + options.js.gsub('"', '\\"') + '","objectGroup":"perus","returnByValue":true}}'
            
            execute([command]) do |message|
                if message.include?('id') && message['id'] == 1
                    if message.include?('result')
                        result = message['result'].to_s
                    elsif message.include?('error')
                        result = message['error'].to_s
                    else
                        result = false
                    end
                end
            end

            result
        end
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
perus-0.1.2 lib/perus/pinger/commands/chrome_execute.rb
perus-0.1.1 lib/perus/pinger/commands/chrome_execute.rb
perus-0.1.0 lib/perus/pinger/commands/chrome_execute.rb