isomorfeus-puppetmaster 0.6.11 → 0.6.14
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/README.md +17 -0
- data/lib/isomorfeus/puppeteer/execution_context.rb +6 -4
- data/lib/isomorfeus/puppetmaster/dsl.rb +7 -7
- data/lib/isomorfeus/puppetmaster/server/executor_middleware.rb +4 -0
- data/lib/isomorfeus/puppetmaster/session.rb +30 -14
- data/lib/isomorfeus/puppetmaster/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 602d8e8f04c6eb2290b4f0bda9bf2c2db5903dfbd86bd0cae7bed3489846378b
         | 
| 4 | 
            +
              data.tar.gz: ca32e34cf20340a0c2039a1b625cffa6d5261313b699dd2a2b536e9b994d2f96
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 1bfc337ba3188881e904feac1ef265a72aad83dee7add3731820cdfb81a940c1b5351963a524df2164f734019ce9e7fb0dfcc6fd1c4c9a85c388add303a419bf
         | 
| 7 | 
            +
              data.tar.gz: 13c2c4858f01844b7cf8bd05ba4d20a04ff25b3d9f3695d2cd8cf178b25501da42e30533df162f6cad778635692058dafc5fd4d221d6bfd32e462a54c072d821
         | 
    
        data/README.md
    CHANGED
    
    | @@ -52,6 +52,16 @@ A document consists of elements. Simply working with just pages, documents and e | |
| 52 52 | 
             
            1. Find something
         | 
| 53 53 | 
             
            2. Interact with it
         | 
| 54 54 |  | 
| 55 | 
            +
            ## Sessions
         | 
| 56 | 
            +
            Using `visit` will open a default session. However, additional browser sessions may be opened with:
         | 
| 57 | 
            +
            ```ruby
         | 
| 58 | 
            +
            s = new_session() # additional args may be passed, like headless: false, devtools: true
         | 
| 59 | 
            +
            # now the session can be interacted with:
         | 
| 60 | 
            +
            s.visit('/')
         | 
| 61 | 
            +
            t = new_session() # multiple sessions may be active at the same time
         | 
| 62 | 
            +
            t.visit('/')
         | 
| 63 | 
            +
            ```
         | 
| 64 | 
            +
             | 
| 55 65 | 
             
            ## Pages
         | 
| 56 66 | 
             
            A page is a Puppeteer::Page and provides its complete API plus some additional convenience methods.
         | 
| 57 67 | 
             
            The drivers opens a empty default page, to use that and go to the apps root page:
         | 
| @@ -75,6 +85,13 @@ Both open pages can then be independently interacted with: | |
| 75 85 | 
             
            page.visit('/go')
         | 
| 76 86 | 
             
            page2.goto('/location')
         | 
| 77 87 | 
             
            ```
         | 
| 88 | 
            +
             | 
| 89 | 
            +
            For debugging:
         | 
| 90 | 
            +
            ```ruby
         | 
| 91 | 
            +
            page.visit('/', headless: false, devtools: true)
         | 
| 92 | 
            +
            ```
         | 
| 93 | 
            +
            This will close the current browser if the options for headless and devtools dont match, and open a new one with the supplied headless and devtools options.
         | 
| 94 | 
            +
             | 
| 78 95 | 
             
            ### Pages and Ruby
         | 
| 79 96 |  | 
| 80 97 | 
             
            Ruby can be executed within pages by simply providing a block or a string:
         | 
| @@ -78,7 +78,7 @@ class Puppeteer::ExecutionContext | |
| 78 78 | 
             
                end
         | 
| 79 79 | 
             
                result, exception = evaluate <<~JAVASCRIPT
         | 
| 80 80 | 
             
                  function () {
         | 
| 81 | 
            -
                    var  | 
| 81 | 
            +
                    var res;
         | 
| 82 82 | 
             
                    var exception = false;
         | 
| 83 83 | 
             
                    if (Opal.await_ruby_exception) {
         | 
| 84 84 | 
             
                      var e = Opal.await_ruby_exception;
         | 
| @@ -87,11 +87,13 @@ class Puppeteer::ExecutionContext | |
| 87 87 | 
             
                      let r = Opal.gvars.promise_result;
         | 
| 88 88 | 
             
                      exception = { message: r.$message(), name: r.$class().$name(), stack: r.$backtrace() }
         | 
| 89 89 | 
             
                    } else if (Opal.gvars.promise_result['$respond_to?']('to_n')) {
         | 
| 90 | 
            -
                       | 
| 91 | 
            -
                    } else {  | 
| 90 | 
            +
                      res = Opal.gvars.promise_result.$to_n()
         | 
| 91 | 
            +
                    } else { res = Opal.gvars.promise_result };
         | 
| 92 92 | 
             
                    delete Opal.gvars.promise_result;
         | 
| 93 93 | 
             
                    delete Opal.gvars.promise_resolved;
         | 
| 94 | 
            -
                     | 
| 94 | 
            +
                    if (res && res.$to_n) { res = res.$to_n(); }
         | 
| 95 | 
            +
                    res = ((res === Opal.nil) ? null : res);
         | 
| 96 | 
            +
                    return [res, exception];
         | 
| 95 97 | 
             
                  }
         | 
| 96 98 | 
             
                JAVASCRIPT
         | 
| 97 99 | 
             
                if exception
         | 
| @@ -3,7 +3,7 @@ module Isomorfeus | |
| 3 3 | 
             
                module DSL
         | 
| 4 4 | 
             
                  @@launch_options = nil
         | 
| 5 5 |  | 
| 6 | 
            -
                  def set_launch_options(app: nil, args: nil, channel: nil, default_viewport: nil, devtools:  | 
| 6 | 
            +
                  def set_launch_options(app: nil, args: nil, channel: nil, default_viewport: nil, devtools: false, dumpio: nil,
         | 
| 7 7 | 
             
                                         env: nil, executable_path: nil, handle_SIGINT: nil, handle_SIGTERM: nil, handle_SIGHUP: nil,
         | 
| 8 8 | 
             
                                         headless: true, ignore_default_args: nil, ignore_https_errors: nil, pipe: nil,
         | 
| 9 9 | 
             
                                         product: :chrome, slow_mo: nil, timeout: nil, user_data_dir: nil)
         | 
| @@ -34,11 +34,11 @@ module Isomorfeus | |
| 34 34 | 
             
                    session.default_page
         | 
| 35 35 | 
             
                  end
         | 
| 36 36 |  | 
| 37 | 
            -
                  def  | 
| 38 | 
            -
                    session. | 
| 37 | 
            +
                  def visit(uri, referer: nil, timeout: nil, wait_until: 'networkidle0', headless: true, devtools: false)
         | 
| 38 | 
            +
                    session(headless: headless, devtools: devtools).visit(uri, referer: referer, timeout: timeout, wait_until: wait_until, headless: headless, devtools: devtools)
         | 
| 39 39 | 
             
                    session.default_page
         | 
| 40 40 | 
             
                  end
         | 
| 41 | 
            -
                  alias_method : | 
| 41 | 
            +
                  alias_method :goto, :visit
         | 
| 42 42 |  | 
| 43 43 | 
             
                  def isomorphic(ruby_source = '', &block)
         | 
| 44 44 | 
             
                    ruby_source = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
         | 
| @@ -56,7 +56,7 @@ module Isomorfeus | |
| 56 56 | 
             
                    Isomorfeus::Puppetmaster.served_app.on_server(ruby_source, &block)
         | 
| 57 57 | 
             
                  end
         | 
| 58 58 |  | 
| 59 | 
            -
                  def new_session(app: nil, args: nil, channel: nil, default_viewport: nil, devtools:  | 
| 59 | 
            +
                  def new_session(app: nil, args: nil, channel: nil, default_viewport: nil, devtools: false, dumpio: nil,
         | 
| 60 60 | 
             
                                  env: nil, executable_path: nil, handle_SIGINT: nil, handle_SIGTERM: nil, handle_SIGHUP: nil,
         | 
| 61 61 | 
             
                                  headless: true, ignore_default_args: nil, ignore_https_errors: nil, pipe: nil,
         | 
| 62 62 | 
             
                                  product: :chrome, slow_mo: nil, timeout: nil, user_data_dir: nil)
         | 
| @@ -109,8 +109,8 @@ module Isomorfeus | |
| 109 109 | 
             
                    Isomorfeus::Puppetmaster.served_app.on_server(ruby_source)
         | 
| 110 110 | 
             
                  end
         | 
| 111 111 |  | 
| 112 | 
            -
                  def session
         | 
| 113 | 
            -
                    @@puppetmaster_session ||= new_session(app: Isomorfeus::Puppetmaster.served_app)
         | 
| 112 | 
            +
                  def session(headless: true, devtools: false)
         | 
| 113 | 
            +
                    @@puppetmaster_session ||= new_session(app: Isomorfeus::Puppetmaster.served_app, headless: headless, devtools: devtools)
         | 
| 114 114 | 
             
                  end
         | 
| 115 115 | 
             
                end
         | 
| 116 116 | 
             
              end
         | 
| @@ -23,6 +23,10 @@ module Isomorfeus | |
| 23 23 | 
             
                                                         'Content-Type' => 'application/json')
         | 
| 24 24 | 
             
                          else
         | 
| 25 25 | 
             
                            begin
         | 
| 26 | 
            +
                              if Isomorfeus.respond_to?(:init_store)
         | 
| 27 | 
            +
                                Isomorfeus.init_store
         | 
| 28 | 
            +
                                Isomorfeus.store.clear! if Isomorfeus.store.respond_to?(:clear!)
         | 
| 29 | 
            +
                              end
         | 
| 26 30 | 
             
                              result = TOPLEVEL_BINDING.eval(request_hash['code']) if request_hash['code']
         | 
| 27 31 | 
             
                              response = Rack::Response.new(Oj.dump({ 'result' => result }),
         | 
| 28 32 | 
             
                                                            200,
         | 
| @@ -4,23 +4,24 @@ module Isomorfeus | |
| 4 4 | 
             
                  TIMEOUT = 30000 # milliseconds
         | 
| 5 5 |  | 
| 6 6 | 
             
                  attr_accessor :app, :browser, :default_page, :product, :response
         | 
| 7 | 
            +
                  attr_reader :headless, :devtools
         | 
| 7 8 |  | 
| 8 | 
            -
                  def initialize(app:, args: nil, channel: nil, default_viewport: nil, devtools:  | 
| 9 | 
            +
                  def initialize(app:, args: nil, channel: nil, default_viewport: nil, devtools: false, dumpio: nil,
         | 
| 9 10 | 
             
                                 env: nil, executable_path: nil, handle_SIGINT: nil, handle_SIGTERM: nil, handle_SIGHUP: nil,
         | 
| 10 11 | 
             
                                 headless: true, ignore_default_args: nil, ignore_https_errors: nil, pipe: nil,
         | 
| 11 12 | 
             
                                 product: :chrome, slow_mo: nil, timeout: nil, user_data_dir: nil)
         | 
| 12 | 
            -
                    @ | 
| 13 | 
            +
                    @parameters = binding.local_variables.map { |v| [v, binding.local_variable_get(v)] }.to_h
         | 
| 14 | 
            +
                    @parameters[:channel] = @parameters[:channel].to_s if channel
         | 
| 15 | 
            +
                    @parameters[:timeout] = TIMEOUT unless timeout
         | 
| 16 | 
            +
                    @app = @parameters.delete(:app)
         | 
| 17 | 
            +
                    @headless = headless
         | 
| 18 | 
            +
                    @devtools = devtools
         | 
| 19 | 
            +
                    @channel = channel
         | 
| 20 | 
            +
                    default_viewport
         | 
| 13 21 | 
             
                    product = product.to_s
         | 
| 14 | 
            -
                    @product = %w[chrome firefox].include?(product) ? product : 'chrome'
         | 
| 15 | 
            -
                    @ | 
| 16 | 
            -
             | 
| 17 | 
            -
                                                  handle_SIGTERM: handle_SIGTERM, handle_SIGHUP: handle_SIGHUP, headless: headless,
         | 
| 18 | 
            -
                                                  ignore_default_args: ignore_default_args, ignore_https_errors: ignore_https_errors,
         | 
| 19 | 
            -
                                                  pipe: pipe, product: product, slow_mo: slow_mo, timeout: timeout ? timeout : TIMEOUT,
         | 
| 20 | 
            -
                                                  user_data_dir: user_data_dir)
         | 
| 21 | 
            -
                    @original_user_agent = @browser.user_agent
         | 
| 22 | 
            -
                    @default_page = @browser.new_page
         | 
| 23 | 
            -
                    @default_page.puppetmaster_session = self
         | 
| 22 | 
            +
                    @parameters[:product] = %w[chrome firefox].include?(product) ? product : 'chrome'
         | 
| 23 | 
            +
                    @product = @parameters[:product]
         | 
| 24 | 
            +
                    launch_browser
         | 
| 24 25 | 
             
                    ObjectSpace.define_finalizer(self, self.class.close_browser(self))
         | 
| 25 26 | 
             
                  end
         | 
| 26 27 |  | 
| @@ -40,12 +41,18 @@ module Isomorfeus | |
| 40 41 | 
             
                    @browser.pages
         | 
| 41 42 | 
             
                  end
         | 
| 42 43 |  | 
| 43 | 
            -
                  def  | 
| 44 | 
            +
                  def visit(uri, referer: nil, timeout: nil, wait_until: 'networkidle0', headless: true, devtools: false)
         | 
| 45 | 
            +
                    if @headless != headless || @devtools != devtools
         | 
| 46 | 
            +
                      @browser.close
         | 
| 47 | 
            +
                      @headless = headless
         | 
| 48 | 
            +
                      @devtools = devtools
         | 
| 49 | 
            +
                      launch_browser
         | 
| 50 | 
            +
                    end
         | 
| 44 51 | 
             
                    parsed_uri = parse_uri(uri)
         | 
| 45 52 | 
             
                    @response = @default_page.goto(parsed_uri.to_s, referer: referer, timeout: timeout, wait_until: wait_until)
         | 
| 46 53 | 
             
                    @default_page
         | 
| 47 54 | 
             
                  end
         | 
| 48 | 
            -
                  alias_method : | 
| 55 | 
            +
                  alias_method :goto, :visit
         | 
| 49 56 |  | 
| 50 57 | 
             
                  def network_conditions
         | 
| 51 58 | 
             
                    ::Puppeteer::NETWORK_CONDITIONS
         | 
| @@ -144,6 +151,15 @@ module Isomorfeus | |
| 144 151 | 
             
                      instance.browser.close if instance.browser
         | 
| 145 152 | 
             
                    end
         | 
| 146 153 | 
             
                  end
         | 
| 154 | 
            +
             | 
| 155 | 
            +
                  def launch_browser
         | 
| 156 | 
            +
                    @parameters[:headless] = @headless
         | 
| 157 | 
            +
                    @parameters[:devtools] = @devtools
         | 
| 158 | 
            +
                    @browser = ::Puppeteer.launch(**@parameters)
         | 
| 159 | 
            +
                    @original_user_agent = @browser.user_agent
         | 
| 160 | 
            +
                    @default_page = @browser.new_page
         | 
| 161 | 
            +
                    @default_page.puppetmaster_session = self
         | 
| 162 | 
            +
                  end
         | 
| 147 163 | 
             
                end
         | 
| 148 164 | 
             
              end
         | 
| 149 165 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: isomorfeus-puppetmaster
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.6. | 
| 4 | 
            +
              version: 0.6.14
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jan Biedermann
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2022-08- | 
| 11 | 
            +
            date: 2022-08-10 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activesupport
         |