Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit eca16be

Browse files
committed
Remove restriction from script execution
1 parent c6b8ab9 commit eca16be

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

lib/remote/RemoteWebDriver.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -152,32 +152,38 @@ public function quit() {
152152
}
153153

154154
/**
155-
* Inject a snippet of JavaScript into the page for execution in the context
156-
* of the currently selected frame. The executed script is assumed to be
157-
* synchronous and the result of evaluating the script will be returned.
155+
* Prepare arguments for JavaScript injection
158156
*
159-
* @param string $script The script to inject.
160-
* @param array $arguments The arguments of the script.
161-
* @return mixed The return value of the script.
157+
* @param array $arguments
158+
* @return array
162159
*/
163-
public function executeScript($script, array $arguments = array()) {
164-
$script = str_replace('"', '\"', $script);
160+
private function prepareScriptArguments(array $arguments)
161+
{
165162
$args = array();
166163
foreach ($arguments as $arg) {
167164
if ($arg instanceof WebDriverElement) {
168165
array_push($args, array('ELEMENT' => $arg->getID()));
169166
} else {
170-
// TODO: Handle the case where arg is a collection
171167
if (is_array($arg)) {
172-
throw new Exception(
173-
"executeScript with collection paramatar is unimplemented"
174-
);
168+
$arg = $this->prepareScriptArguments($arg);
175169
}
176170
array_push($args, $arg);
177171
}
178172
}
173+
return $args;
174+
}
179175

180-
$params = array('script' => $script, 'args' => $args);
176+
/**
177+
* Inject a snippet of JavaScript into the page for execution in the context
178+
* of the currently selected frame. The executed script is assumed to be
179+
* synchronous and the result of evaluating the script will be returned.
180+
*
181+
* @param string $script The script to inject.
182+
* @param array $arguments The arguments of the script.
183+
* @return mixed The return value of the script.
184+
*/
185+
public function executeScript($script, array $arguments = array()) {
186+
$params = array('script' => $script, 'args' => $this->prepareScriptArguments($arguments));
181187
$response = $this->executor->execute('executeScript', $params);
182188
return $response;
183189
}

0 commit comments

Comments
 (0)