New issue
Advanced search Search tips
Starred by 1 user

Issue metadata

Status: Duplicate
Merged: issue 1344
Owner: ----
Closed: Apr 2016



Sign in to add a comment

When calling `setSize` in selenium-webdriver (nodejs), error thrown: "... 'unsafe-eval' is not an allowed source"

Reported by dy...@shyp.com, Apr 6 2016

Issue description

OS: OSX 10.11.3
Selenium Version: selenium-webdriver (node) 2.53.1
Browser: Chrome 51.0.2700.0 dev, ChromeDriver 2.21.371459
Node.js v4.3.1

Issue Description:
Calling `setSize` throws an exception regarding the use of `eval` / content security policy. Note that in the repro steps I haven't navigated to a page yet, thought the same error is thrown if I do navigate beforehand.

Steps to reproduce:
testcase.js:
```
const webdriver = require('selenium-webdriver');
const driver = new webdriver.Builder().withCapabilities({ browserName: 'chrome' }).build();

driver.manage().window().setSize(1024, 768);
```

```
$ node testcase.js
/Users/dylan/dev/shyp.com/node_modules/selenium-webdriver/lib/promise.js:654
    throw error;
    ^

WebDriverError: unknown error: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' blob: filesystem: chrome-extension-resource:".

JavaScript stack:
EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' blob: filesystem: chrome-extension-resource:".

    at executeAsyncScript (<anonymous>:329:5)
    at apply.height (<anonymous>:345:29)
    at callFunction (<anonymous>:237:33)
    at apply.height (<anonymous>:247:23)
    at <anonymous>:248:3
  (Session info: chrome=51.0.2700.0)
  (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Mac OS X 10.11.3 x86_64)
    at WebDriverError (/Users/dylan/dev/shyp.com/node_modules/selenium-webdriver/lib/error.js:27:10)
    at Object.checkLegacyResponse (/Users/dylan/dev/shyp.com/node_modules/selenium-webdriver/lib/error.js:639:15)
    at parseHttpResponse (/Users/dylan/dev/shyp.com/node_modules/selenium-webdriver/http/index.js:528:13)
    at /Users/dylan/dev/shyp.com/node_modules/selenium-webdriver/http/index.js:466:11
    at ManagedPromise.invokeCallback_ (/Users/dylan/dev/shyp.com/node_modules/selenium-webdriver/lib/promise.js:1343:14)
    at TaskQueue.execute_ (/Users/dylan/dev/shyp.com/node_modules/selenium-webdriver/lib/promise.js:2868:14)
    at TaskQueue.executeNext_ (/Users/dylan/dev/shyp.com/node_modules/selenium-webdriver/lib/promise.js:2851:21)
    at /Users/dylan/dev/shyp.com/node_modules/selenium-webdriver/lib/promise.js:2775:25
    at /Users/dylan/dev/shyp.com/node_modules/selenium-webdriver/lib/promise.js:639:7
    at process._tickCallback (node.js:364:9)
From: Task: WebDriver.manage().window().setSize(1024, 768)
    at Driver.schedule (/Users/dylan/dev/shyp.com/node_modules/selenium-webdriver/lib/webdriver.js:386:17)
    at Window.setSize (/Users/dylan/dev/shyp.com/node_modules/selenium-webdriver/lib/webdriver.js:1404:25)
    at Object.<anonymous> (/Users/dylan/dev/shyp.com/testcase.js:4:26)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:134:18)
    at node.js:962:3
```



 

Comment 1 by dy...@shyp.com, Apr 6 2016

A bit more searching suggests this may be the same issue as https://bugs.chromium.org/p/chromedriver/issues/detail?id=1344

Comment 2 by dy...@shyp.com, Apr 6 2016

I don't know the chromedriver internals at all, but I *think* that resolving this may be as simple as adding the following line to https://chromium.googlesource.com/chromium/chromium/+/master/chrome/test/webdriver/test/page_action_extension/manifest.json

```
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
```

— or, rewriting setSize to no longer use eval.
Project Member

Comment 3 by gmanikpure@chromium.org, Apr 6 2016

Mergedinto: 1344
Status: Duplicate (was: Unconfirmed)

Sign in to add a comment