open(url [, options, callback])
Opens the webpage at url
.
const url = "https://phantombuster.com/"
try {
const [httpCode, httpStatus] = await tab.open(url)
if ((httpCode >= 300) || (httpCode < 200)) {
console.log("The site responded with", httpCode, httpStatus)
} else {
console.log("Successfully opened", url, ":", httpCode, httpStatus)
// Manipulate the page in this branch
// You should probably do a waitUntilVisible() or waitUntilPresent() here
}
} catch(err) {
console.log("Could not open page:", err)
}
const url = "https://phantombuster.com/"
tab.open(url)
.then((httpCode, httpStatus) => {
if ((httpCode >= 300) || (httpCode < 200)) {
console.log("The site responded with", httpCode, httpStatus)
} else {
console.log("Successfully opened", url,":", httpCode, httpStatus)
// Manipulate the page in this branch
// You should probably do a waitUntilVisible() or waitUntilPresent() here
}
})
.catch((err, httpCode, httpStatus) => {
console.log("Could not open page:", err)
})
var url = "https://phantombuster.com/"
tab.open(url, function(err, httpCode, httpStatus, url) {
if (err) {
console.log("Could not open page:", err)
} else if ((httpCode >= 300) || (httpCode < 200)) {
console.log("The site responded with", httpCode, httpStatus)
} else {
console.log("Successfully opened", url, ":", httpCode, httpStatus)
// Manipulate the page in this branch
// You should probably do a waitUntilVisible() or waitUntilPresent() here
}
});
Opening a page will time out after 10 seconds. This can be changed with the timeout
Nick option (see Nick's options). Note: this time out concerns the initial page but not the resources the page requires thereafter.
— url (String)
(String)
URL of the page to open. Should begin with http://
or https://
(or file://
to open a page that was previously downloaded to your agent's disk).
— [options] (PlainObject)
(PlainObject)
Request configuration (optional). At this time, this object is ignored by the Chrome driver, it only has an effect with the CasperJS driver.
{
method: "post",
data: {
"some param": "some data",
"another field": "this is sent in x-www-form-urlencoded format"
},
headers: {
"Accept-Language": "fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3"
}
}
— callback (Function(err, httpCode, httpStatus, url))
(Function(err, httpCode, httpStatus, url))
Function called when finished (optional).
err (String)
:null
or a description of what went wrong if something went wrong (typically if there was a network error or timeout)httpCode (Number)
: the received HTTP code ornull
if there was a network errorhttpStatus (String)
: text equivalent of the received HTTP code ornull
if there was a network error — can sometimes be an empty string ornull
even when the request was successful, do not use this value for something criticalurl (String)
: the actually opened URL (can be different from the input URL in case of 3xx redirects for example) ornull
if there was a network error
Know your errors
This method will NOT return an error when the received HTTP isn't 200. An error is returned only when a network error happens. It's your job to check for 404s or 500s with
httpCode
if needed.
Always wait for DOM elements
Many pages on the web load slowly and unreliably. Many more make numerous aynchronous queries. For these reasons, you should always wait for the DOM elements that interest you after opening a page with
waitUntilVisible()
orwaitUntilPresent()
.