@@ -16,35 +16,6 @@ module Runtime
1616 INTERMITTENT_ATTEMPTS = ENV . fetch ( "FERRUM_INTERMITTENT_ATTEMPTS" , 6 ) . to_i
1717 INTERMITTENT_SLEEP = ENV . fetch ( "FERRUM_INTERMITTENT_SLEEP" , 0.1 ) . to_f
1818
19- SCRIPT_SRC_TAG = <<~JS
20- const script = document.createElement("script");
21- script.src = arguments[0];
22- script.type = arguments[1];
23- script.onload = arguments[2];
24- document.head.appendChild(script);
25- JS
26- SCRIPT_TEXT_TAG = <<~JS
27- const script = document.createElement("script");
28- script.text = arguments[0];
29- script.type = arguments[1];
30- document.head.appendChild(script);
31- arguments[2]();
32- JS
33- STYLE_TAG = <<~JS
34- const style = document.createElement("style");
35- style.type = "text/css";
36- style.appendChild(document.createTextNode(arguments[0]));
37- document.head.appendChild(style);
38- arguments[1]();
39- JS
40- LINK_TAG = <<~JS
41- const link = document.createElement("link");
42- link.rel = "stylesheet";
43- link.href = arguments[0];
44- link.onload = arguments[1];
45- document.head.appendChild(link);
46- JS
47-
4819 #
4920 # Evaluate and return result for given JS expression.
5021 #
@@ -126,60 +97,6 @@ def evaluate_on(node:, expression:, by_value: true, wait: 0)
12697 call ( expression : expression , on : node , wait : wait , **options )
12798 end
12899
129- #
130- # Adds a `<script>` tag to the document.
131- #
132- # @param [String, nil] url
133- #
134- # @param [String, nil] path
135- #
136- # @param [String, nil] content
137- #
138- # @param [String] type
139- #
140- # @example
141- # browser.add_script_tag(url: "http://example.com/stylesheet.css") # => true
142- #
143- def add_script_tag ( url : nil , path : nil , content : nil , type : "text/javascript" )
144- expr , *args = if url
145- [ SCRIPT_SRC_TAG , url , type ]
146- elsif path || content
147- if path
148- content = File . read ( path )
149- content += "\n //# sourceURL=#{ path } "
150- end
151- [ SCRIPT_TEXT_TAG , content , type ]
152- end
153-
154- evaluate_async ( expr , @page . timeout , *args )
155- end
156-
157- #
158- # Adds a `<style>` tag to the document.
159- #
160- # @param [String, nil] url
161- #
162- # @param [String, nil] path
163- #
164- # @param [String, nil] content
165- #
166- # @example
167- # browser.add_style_tag(content: "h1 { font-size: 40px; }") # => true
168- #
169- def add_style_tag ( url : nil , path : nil , content : nil )
170- expr , *args = if url
171- [ LINK_TAG , url ]
172- elsif path || content
173- if path
174- content = File . read ( path )
175- content += "\n //# sourceURL=#{ path } "
176- end
177- [ STYLE_TAG , content ]
178- end
179-
180- evaluate_async ( expr , @page . timeout , *args )
181- end
182-
183100 private
184101
185102 def call ( expression :, arguments : [ ] , on : nil , wait : 0 , handle : true , **options )
0 commit comments