The document discusses PhantomJS, an open-source headless WebKit browser that allows for automating web page interaction and rendering using JavaScript. It can be used to capture screenshots, render PDFs, and test pages without needing a browser UI. The document provides examples of using PhantomJS to log messages, capture screenshots, and extract data from web pages. It also discusses how PhantomJS integrates with frameworks like Capybara to enable automated testing of web applications.
11. Ariya Hidayat
VP of Engineering at @ShapeSecurity
Doctorate degree (with great honor) in Electrical Engineering
from University of Paderborn (Germany)
Master degree from Institute of Technology Bandung (Indonesia)
with an exchange program with Technical University Munich (Germany)
Bachelor degree (with honor) from Institute of Technology Bandung (Indonesia)
Indonesian, English, German
Indonesia → Mountain View, California
@AriyaHidayat
12. Qt WebKit
JavaScript
API Engine
Web
Server
Mongoose
Ghost Driver
Remote
Selenium WebDriver
(Wire Protocol)
JavaScript
Engine
13.
14. $ ls -l phantomjs-1.9.7-linux-x86_64/bin
total 74896
-rwxr-xr-x@ 1 vassilevsky staff 38346752 26 янв 2014 phantomjs
X11 (v1.5+)
freetype
fontconfig
28. JS API
class Poltergeist.Connection
constructor: (@owner, @port) ->
@socket = new WebSocket "ws://127.0.0.1:#{@port}/"
@socket.onmessage = this.commandReceived
@socket.onclose = -> phantom.exit()
WebKit
module Capybara::Poltergeist
class Server
attr_reader :socket, :fixed_port, :timeout
def start
@socket = WebSocketServer.new(fixed_port, timeout)
end
def send(message)
@socket.send(message) or raise DeadClient.new(message)
end
end
end
29. class Poltergeist.WebPage
onErrorNative: (message, stack) ->
stackString = message
stack.forEach (frame) ->
stackString += "n"
stackString += " at #{frame.file}:#{frame.line}"
stackString += " in #{frame.function}" if frame.function && frame.function != ''
@errors.push(message: message, stack: stackString)
class Poltergeist.Browser
sendResponse: (response) ->
errors = @currentPage.errors
@currentPage.clearErrors()
if errors.length > 0 && @js_errors
@owner.sendError(new Poltergeist.JavascriptError(errors))
else
@owner.sendResponse(response)