拒绝将字符串评估为 JavaScript 因为 'unsafe-eval'
Refused to evaluate a string as JavaScript because 'unsafe-eval'
大家好,我正在使用 phantomjs
进行自动化测试。这是我的代码:
capabilities = Selenium::WebDriver::Remote::Capabilities.phantomjs("phantomjs.page.settings.userAgent" => "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36")
proxies = ['--ignore-ssl-errors=true', '--web-security=false', '--ssl-protocol=any']
driver = Selenium::WebDriver.for :phantomjs, :desired_capabilities => capabilities , :args => proxies
browser = Watir::Browser.new driver
begin
browser.goto(url)
browser.goto url
browser.driver.execute_script( "window.scrollBy(0,document.body.scrollHeight/2)" )
sleep 1
browser.driver.execute_script( "window.scrollBy(0,document.body.scrollHeight)" )
sleep 1
response = browser.html
fileHtml = File.new("response_linkedin.html", "wb+")
fileHtml.puts(response)
fileHtml.close
browser.close
response
rescue Exception => e
raise e.message.to_s
ensure
browser.close
end
问题是当我尝试执行脚本 window.scrollBy(0,document.body.scrollHeight/2)
来滚动 window 时,我的代码返回如下错误:
"errorMessage":"Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive
我想知道为什么我不能 运行 在 phantomjs
中编写脚本?注意事项:我正在使用 phantomjs
2.2.1 版,有些人建议我降级 1.9.8 版 (source),不幸的是降级到 1.9.8 版似乎不起作用。有人可以帮助我吗?
phantomjs 应该没有问题运行javascript
- 尝试 watir-scroll,如果您需要使用 Watir 在视口中移动,这将改变生活。
使用最新版本的 Watir,您现在可以轻松试用最新的 Chrome Headless 功能:
Watir.browser.new(:chrome, {headless: true, args: args}
有了 phantomjs maintainer stepping down,Chrome 和 Firefox 中的无头功能将投入更多精力。
大家好,我正在使用 phantomjs
进行自动化测试。这是我的代码:
capabilities = Selenium::WebDriver::Remote::Capabilities.phantomjs("phantomjs.page.settings.userAgent" => "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36")
proxies = ['--ignore-ssl-errors=true', '--web-security=false', '--ssl-protocol=any']
driver = Selenium::WebDriver.for :phantomjs, :desired_capabilities => capabilities , :args => proxies
browser = Watir::Browser.new driver
begin
browser.goto(url)
browser.goto url
browser.driver.execute_script( "window.scrollBy(0,document.body.scrollHeight/2)" )
sleep 1
browser.driver.execute_script( "window.scrollBy(0,document.body.scrollHeight)" )
sleep 1
response = browser.html
fileHtml = File.new("response_linkedin.html", "wb+")
fileHtml.puts(response)
fileHtml.close
browser.close
response
rescue Exception => e
raise e.message.to_s
ensure
browser.close
end
问题是当我尝试执行脚本 window.scrollBy(0,document.body.scrollHeight/2)
来滚动 window 时,我的代码返回如下错误:
"errorMessage":"Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive
我想知道为什么我不能 运行 在 phantomjs
中编写脚本?注意事项:我正在使用 phantomjs
2.2.1 版,有些人建议我降级 1.9.8 版 (source),不幸的是降级到 1.9.8 版似乎不起作用。有人可以帮助我吗?
phantomjs 应该没有问题运行javascript
- 尝试 watir-scroll,如果您需要使用 Watir 在视口中移动,这将改变生活。
使用最新版本的 Watir,您现在可以轻松试用最新的 Chrome Headless 功能:
Watir.browser.new(:chrome, {headless: true, args: args}
有了 phantomjs maintainer stepping down,Chrome 和 Firefox 中的无头功能将投入更多精力。