isomorfeus-puppetmaster 0.6.11 → 0.6.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 656b7484c3a3374788538f78c562495d2d699fa908aec6df0d9fa4471fab4204
4
- data.tar.gz: 4674345287625664ad840781759c88caa18832c271f3540acee8973620b74d58
3
+ metadata.gz: 602d8e8f04c6eb2290b4f0bda9bf2c2db5903dfbd86bd0cae7bed3489846378b
4
+ data.tar.gz: ca32e34cf20340a0c2039a1b625cffa6d5261313b699dd2a2b536e9b994d2f96
5
5
  SHA512:
6
- metadata.gz: c0f161a5fdd048be31f8d74b7fe858d0cdad460812a233a339fd5cafe256fdcaabde6d19c862ab22e98597b265684d123704303b7920dd9cc24b93b8be7fb192
7
- data.tar.gz: 7265b2afc7c569032882ef782ae31ea4bd8766f34d773d2d76e98979e36346d689820c5e0da91358dec7cfb7ccf2b9f2f72187fe31af911146410c198696bfa7
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 result;
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
- result = Opal.gvars.promise_result.$to_n()
91
- } else { result = Opal.gvars.promise_result };
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
- return [result, exception];
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: nil, dumpio: nil,
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 goto(uri, referer: nil, timeout: nil, wait_until: 'networkidle0')
38
- session.goto(uri, referer: referer, timeout: timeout, wait_until: wait_until)
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 :visit, :goto
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: nil, dumpio: nil,
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: nil, dumpio: nil,
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
- @app = app
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
- @browser = ::Puppeteer.launch(args: args, channel: channel&.to_s, devtools: devtools, default_viewport: default_viewport,
16
- dumpio: dumpio, env: env, executable_path: executable_path, handle_SIGINT: handle_SIGINT,
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 goto(uri, referer: nil, timeout: nil, wait_until: 'networkidle0')
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 :visit, :goto
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
@@ -1,3 +1,3 @@
1
1
  module Isomorfeus
2
- PUPPETMASTER_VERSION = '0.6.11'
2
+ PUPPETMASTER_VERSION = '0.6.14'
3
3
  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.11
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-07 00:00:00.000000000 Z
11
+ date: 2022-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport