Javascript error
sashazykov opened this issue · 6 comments
I am getting the error:
One or more errors were raised in the Javascript code on the page. If you don't care about these errors, you can ignore them by setting js_errors: false in your Poltergeist configuration (see documentation for details). ReferenceError: Can't find variable: org ReferenceError: Can't find variable: org at https://www.tradview.com/static/js/chatclient_widget.c001027b8.js:4358
Is it possible to somehow ignore it?
Capybara::Poltergeist::JavascriptError
exception type
Strange, which URL raised the JS error? By default JS errors are ignored, see:
https://github.com/vitalie/webshot/blob/master/lib/webshot.rb#L40
http://www.uleshi.ru/ for example:
Capybara::Poltergeist::JavascriptError: One or more errors were raised in the Javascript code on the page. If you don't care about these errors, you can ignore them by setting js_errors: false in your Poltergeist configuration (see documentation for details). ReferenceError: Can't find variable: fulltime ReferenceError: Can't find variable: fulltime at http://www.uleshi.ru/:147 SyntaxError: Parse error SyntaxError: Parse error
or this one http://gadishot.blogspot.de/
Capybara::Poltergeist::JavascriptError: One or more errors were raised in the Javascript code on the page. If you don't care about these errors, you can ignore them by setting js_errors: false in your Poltergeist configuration (see documentation for details). TypeError: 'undefined' is not an object (evaluating 'entry.title') TypeError: 'undefined' is not an object (evaluating 'entry.title') at http://gadishot.blogspot.de/:566 in showrecentposts4 at http://gadishot.blogspot.de/feeds/posts/default/-/Artikel?max-results=1&orderby=published&alt=json-in-script&callback=showrecentposts4:2 TypeError: 'undefined' is not an object (evaluating 'entry.title') TypeError: 'undefined' is not an object (evaluating 'entry.title') at http://gadishot.blogspot.de/:349 in showrecentposts2 at http://gadishot.blogspot.de/feeds/posts/default/-/infotainment?max-results=1&orderby=published&alt=json-in-script&callback=showrecentposts2:2 TypeError: 'undefined' is not an object (evaluating 'entry.title') TypeError: 'undefined' is not an object (evaluating 'entry.title') at http://gadishot.blogspot.de/:1290 in showrecentposts8 at http://gadishot.blogspot.de/feeds/posts/default/-/video?max-results=4&orderby=published&alt=json-in-script&callback=showrecentposts8:2 TypeError: 'undefined' is not an object (evaluating 'entry.title') TypeError: 'undefined' is not an object (evaluating 'entry.title') at http://gadishot.blogspot.de/:786 in showrecentposts5 at http://gadishot.blogspot.de/feeds/posts/default/-/Life%20Style?max-results=2&orderby=published&alt=json-in-script&callback=showrecentposts5:2
I can't reproduce your problem:
# File: t.rb
require 'webshot'
ws = Webshot::Screenshot.instance
ws.capture ARGV.first, "output.png"
$ ruby -v
ruby 1.9.3p545 (2014-02-24 revision 45159) [x86_64-linux]
$ phantomjs --version
1.9.7
$ ruby t.rb http://www.uleshi.ru/
Unsafe JavaScript attempt to access frame with URL http://www.uleshi.ru/ from frame with URL http://www.ustream.tv/embed/10985073. Domains, protocols and ports must match.
$ ruby t.rb http://gadishot.blogspot.de/
Invalid App Id: Must be a number or numeric string representing the application id.
FB.getLoginStatus() called before calling FB.init().
[...]
$ rails c
Loading development environment (Rails 3.2.18)
2.0.0-p481 :001 > Webshot::Screenshot.instance.capture('http://www.uleshi.ru/', "/tmp/thumb.png", width: 1024, height: 768)
2014-05-30 23:18:09.096 phantomjs[5538:507] CoreText performance note: Client called CTFontCreateWithName() using name "Arial" and got font with PostScript name "ArialMT". For best performance, only use PostScript names when calling this API.
2014-05-30 23:18:09.096 phantomjs[5538:507] CoreText performance note: Set a breakpoint on CTFontLogSuboptimalRequest to debug.
2014-05-30 23:18:09.904 phantomjs[5538:507] CoreText performance note: Client called CTFontCreateWithName() using name "Times New Roman" and got font with PostScript name "TimesNewRomanPSMT". For best performance, only use PostScript names when calling this API.
PhantomJS has crashed. Please read the crash reporting guide at https://github.com/ariya/phantomjs/wiki/Crash-Reporting and file a bug report at https://github.com/ariya/phantomjs/issues/new with the crash dump file attached: /tmp/6ECD4D02-C041-460E-BC15-7A504780E742.dmp
Webshot::WebshotError: Capybara error: "PhantomJS client died while processing {\"name\":\"visit\",\"args\":[\"http://www.uleshi.ru/\"]}"
from /Users/sashazykov/.rvm/gems/ruby-2.0.0-p481/gems/webshot-0.0.5/lib/webshot/screenshot.rb:81:in `rescue in capture'
from /Users/sashazykov/.rvm/gems/ruby-2.0.0-p481/gems/webshot-0.0.5/lib/webshot/screenshot.rb:30:in `capture'
from (irb):1
from /Users/sashazykov/.rvm/gems/ruby-2.0.0-p481/gems/railties-3.2.18/lib/rails/commands/console.rb:47:in `start'
from /Users/sashazykov/.rvm/gems/ruby-2.0.0-p481/gems/railties-3.2.18/lib/rails/commands/console.rb:8:in `start'
from /Users/sashazykov/.rvm/gems/ruby-2.0.0-p481/gems/railties-3.2.18/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
ruby 2.0.0-p481 / 2.0.0-p451
phantomjs 1.9.2 / 1.9.7
webshot 0.0.5
poltergeist 1.5.0
capybara 2.1.0
I've repeated the test without any luck:
- ruby 2.0.0p451
- phantomjs 1.9.7
- webshot 0.0.5
- capybara 2.2.1
- poltergeist 1.5.0
I wouldn't recommend running it directly from Rails, you
should isolate it in a small application which exposes the service
through an API (sinatra, grape, ...) and treat it as unreliable
because sometimes the PhantomJS crashes.
You should have enough CPU and memory to generate
thumbnails. See the issue #2 for the setup I'm using currently.