@@ -22,6 +22,31 @@ module WebDriver
22
22
module DriverExtensions
23
23
module HasPinnedScripts
24
24
25
+ #
26
+ # Returns the list of all pinned scripts.
27
+ #
28
+ # @return [Array<DevTools::PinnedScript>]
29
+ #
30
+
31
+ def pinned_scripts
32
+ @pinned_scripts ||= [ ]
33
+ end
34
+
35
+ #
36
+ # Pins JavaScript snippet that is available during the whole
37
+ # session on every page. This allows to store and call
38
+ # scripts without sending them over the wire every time.
39
+ #
40
+ # @example
41
+ # script = driver.pin_script('return window.location.href')
42
+ # driver.execute_script(script)
43
+ # # navigate to a new page
44
+ # driver.execute_script(script)
45
+ #
46
+ # @param [String] script
47
+ # @return [DevTools::PinnedScript]
48
+ #
49
+
25
50
def pin_script ( script )
26
51
script = DevTools ::PinnedScript . new ( script )
27
52
pinned_scripts << script
@@ -34,26 +59,18 @@ def pin_script(script)
34
59
script
35
60
end
36
61
62
+ #
63
+ # Unpins script making it undefined for the subsequent calls.
64
+ #
65
+ # @param [DevTools::PinnedScript]
66
+ #
67
+
37
68
def unpin_script ( script )
38
69
devtools . runtime . evaluate ( expression : script . remove )
39
70
devtools . page . remove_script_to_evaluate_on_new_document ( identifier : script . devtools_identifier )
40
71
pinned_scripts . delete ( script )
41
72
end
42
73
43
- def pinned_scripts
44
- @pinned_scripts ||= [ ]
45
- end
46
-
47
- def execute_script ( script , *args )
48
- script = script . call if script . is_a? ( DevTools ::PinnedScript )
49
- super ( script , *args )
50
- end
51
-
52
- def execute_async_script ( script , *args )
53
- script = script . call if script . is_a? ( DevTools ::PinnedScript )
54
- super ( script , *args )
55
- end
56
-
57
74
end # HasPinnedScripts
58
75
end # DriverExtensions
59
76
end # WebDriver
0 commit comments