This documentation is for the HTTP based Standard JSON API. For POST
requests made in any programming language, (you can use GET
in a pinch too)
There are some important considerations when you call a browser from an API. Here are some tips to improve your performance and get what you want.
requestSettings:{"doneWhen":[{ "event":"domReady"},]}
as shown in this example. That page loads in about 6 seconds, where the original without domReady loads in about 20 seconds. The difference is that we render when the browser signals domReady. Normally we wait until all resources (ads,css,images,etc) are loaded.pjsc-billing-*
headers.pjsc-content-resource-*
headers.outputAsJson:true
property. This will return your content and all details about load times, cookies, iFrames, sub resources, etc.renderType:"jpeg, outputAsJson:true
. The image will be base64 encoded. The html will be shown under the main frame contents.This api allows unparalleled control over your browser request. Using this Automation API you will be able to do the following things easily:
ES2018
javascript) execution inside your API call. This enables dynamic query/manipulation of the page. Full control over the browser.See the New Automation API Docs for more information.
To use this API, you need to submit a GET
or POST
request to the API endpoint. GET
requests are the simplest way of showing examples and getting started, but it is strongly suggested you use the POST
endpoint for "real" usage, because GET
requests have a limited length and you need to escape special characters like ?
.
Submit your IPageRequest as a HTTP POST request.
[YOUR-KEY]
/[REQUEST-JSON]
application/json
Basic GET using uriComponent encoded requests
[YOUR-KEY]
/?request=[REQUEST-JSON]
[REQUEST-JSON]
should be encoded via encodeURIComponent()
, do not encode the parts individually.[YOUR-KEY]
/?requestBase64=[REQUEST-JSON]
[REQUEST-JSON]
should be Base64 Encoded, do not encode the parts individually, and do not urlEncode before you Base64 Encode.[YOUR-KEY]
Your key used for creditBalance/billing. You can obtain this by signing up, or use the special key a-demo-key-with-low-quota-per-ip-address
for testing.
[REQUEST-JSON]
The details of your request as a JSON object. This JSON can take the following form:
{url:"http://www.example.com",renderType:"jpg",outputAsJson:true}
DEPRECATED The following Request-JSON forms are deprecated in favor of the new Automation API, but you can still use them if you need:
[{url:"http://www.google.com"},{url:"https://www.google.com/doodles/",renderType:"jpg",outputAsJson:true}]
{proxy:false,pages:[{url:"http://www.google.com"},{url:"https://www.google.com/doodles/",renderType:"jpg",outputAsJson:true}]}
While the url
is required in a IPageRequest, everything else is optional. Click here to view the default values if you leave the various parameters blank
These examples use GET
requests because they are the simplest way of showing examples and getting started, but it is strongly suggested you use the POST
endpoint for "real" usage.
{url:"http://www.highcharts.com/demo/pie-donut",renderType:"jpg"}
Use png
if you need transparency (if the backgrounds are weirdly black){url:"http://amazon.com",renderType:"pdf"}
Important: If the pdf doesn't look correct, consider setting IRenderSettings.emulateMedia to "print". The default is "screen", which improves compatibility with older sites.{url:"http://www.example.com",renderType:"plainText",outputAsJson:true}
See the output pageResponse.pageRequest
for the default values to other parameters.{url:"https://www.example.com/",outputAsJson:true,renderType:"plainText",suppressJson:["pageResponses","content","meta.trace","originalRequest"],queryJson:["pageResponses.events[key='requestFinished']","content.data"]}
Use the IPageRequest.suppressJson and IPageRequest.queryJson feature to reduse outputAsJson
verbosity.{url:"http://www.highcharts.com/demo/pie-donut",renderType:"jpg",renderSettings:{zoomFactor:2}}
Same as using the zoom (Ctrl +) feature in Chrome. For more info, see IRenderSettings.zoomFactor.{url:"http://localhost/examples/corpus/flower.png",renderType:"png",renderSettings:{selector:"img"}}
runs the CSS Selector and clips the output to the dimensions of the img
tag. For more info, see IRenderSettings.selector and this MDN page on using selectors{url:"http://www.cnn.com/",renderType:"jpeg",renderSettings:{viewport:{width:640,height:500},clipRectangle:{width:640,height:500},zoomFactor:0.45}}
Sets IRenderSettings.viewport to 640px width, zooms out, and sets a 640x500 IRenderSettings.clipRectangle to generate a thumbnail image of the CNN.com website.{url:"http://localhost/blank",content:"<h1>HelloWorld!</h1>",renderType:"jpg"}
Upload html and render it as if it were loaded from a URL. See IPageRequest.content for more info.{url:"http://www.highcharts.com/demo/pie-donut",renderType:"jpg",requestSettings:{resourceModifier:[{regex:".*highcharts.com.*",changeUrl:"$$protocol:$$port//en.wikipedia.org/wiki$$path"}]}}
The target domain www.highcharts.com
has been replaced with wikipedia.org
but the path is preserved. read the text of the output error message to see this. See IRequestSettings.resourceModifier for more info.{url:"http://amazon.com",renderType:"jpg",requestSettings:{resourceModifier:[{regex:".*css.*",isBlacklisted:true}],clearCache:true}}
Note the use of the IRequestSettings.clearCache parameter. This is required so that .css resources are re-requested and blocked.pageResponses.cookies
property.clearCache:true
parameter. This is required so that all resources are re-requested so headers are populated.Referer
header in the resulting HTML.Hello:world
and Accept-encoding:tacos
values in the resulting HTML. Uses our example show request details pageoutputAsJson:true
or you will not get usable resultsapplication/json
content-type and submit POST data. Check the payload
section of the output results.{url:'http://phantomjscloud.com/examples/helpers/auth',renderType:'plainText',requestSettings:{authentication:{userName:"hello",password:"world"}}}
See the headers.authorization
node in the output for login credentialsIMPORTANT NOTE ON SCRIPTS The Script API is deprecated. While it will continue to work, we suggest you switch to The New Automation API. The Automation API is easier to use and more powerful.
Please see the Automation API Examples.
eldiariomontanes.es
site lazy loads images only when it's shown in the browser, so if you take a screenshot without the provided script, the bottom part will be missing images. Important: This page takes aprox 25 seconds to load, and weighs aprox 2mb in size. (Costs about 0.0047 credits)The following examples use IPageRequest.proxy which is an "easy to use shortcut" to common proxy settings.
{ url:"https://phantomjscloud.com/examples/helpers/requestdata", proxy:"geo-us"}
* Costs an additional $0.25/gb ingress. All Requests from a single, Static IP (35.188.112.61
) in the USA. { url:"https://phantomjscloud.com/examples/helpers/requestdata", proxy:"anon-any"}
* Costs an additional $0.50/gb ingress. Other location choices include cn
(China), nl
(Netherlands), us
(USA), in
(India), and more. A full list of locations can be found here{ url:"https://phantomjscloud.com/examples/helpers/requestdata", proxy:"custom-http://myProxy.com:8838:myname:secret"}
* No additional cost to use a 3rd party proxy.If you want full customization of proxy settings use IProxyOptions as shown in this example:
35.188.112.61
) and then relays the request to a custom proxy serverThese pages are used in some of the above examples, and might be useful to you when evaluating this service:
Please refer to the main Docs Index Page for Basic Troubleshooting, Testing and Performance Optimization, Usage FAQ, and language-specific samples.
renderSettings.shadowDom:"import"
is now the default, displaying the html contents of ShadowDom in the content html.OutputAsJson:true
now includes all cookies, not just ones visible by the page javascript.scripts
and _pjscMeta
the different event phases that a page goes through
new for Chrome backend. summary of all resources requested during the page execution, and their current status upon page completion.
aborted because the resource exceeded IRequestSettings.resourceTimeout
requests that were still active (but healthy) upon page completion
successfully completed resource loads
failed due to normal browser workflows
requests that were still active (but took longer than IRequestSettings.resourceWait) upon page completion
if the browser looses track of resource request/response pairs, it will be put here (should never happen)
select the browser engine you will use
you may choose from the following shortcuts: "
default
", "preview
", "webkit
", "chrome
"default
: currently points tochrome
preview
: currentlychrome
. may change at any time as this is for testing new backends or feature enhancements.webkit
: the latest stabke version of the default PhantomJs rendering engine:webkit pjs2.1.1
chrome
: the latest stable version of chromeor choose a specific backend:
chrome
,webkit pjs2.1.1
,webkit pjs2.5beta