inject(urlOrPath [, callback])
Injects a script in the current DOM page context.
The script can be stored locally on disk or on a remote server.
— urlOrPath (String)
(String)
Path to a local or remote script.
— callback (Function(err))
(Function(err))
Function called when finished (optional).
err (String)
:null
or a description of what went wrong if something went wrong
const urlOrPath = "https://code.jquery.com/jquery-3.2.1.min.js"
try {
await tab.inject(urlOrPath)
console.log("Jquery script inserted!")
//You may now use tab.evaluate() and use jQuery functions
} catch (err) {
console.log("Could not inject jQuery:", err)
}
const urlOrPath = "https://code.jquery.com/jquery-3.2.1.min.js"
tab.inject(urlOrPath)
.then(() => {
console.log("Jquery script inserted!")
//You may now use tab.evaluate() and use jQuery functions
})
.catch((err) => {
console.log("Could not inject jQuery:", err)
})
var urlOrPath = "https://code.jquery.com/jquery-3.2.1.min.js"
tab.inject(urlOrPath, function(err) {
if (err) {
console.log("Could not inject jQuery:", err)
}
else {
console.log("Jquery script inserted!")
//You may now use tab.evaluate() and use jQuery functions
}
})
Phantombuster
When using NickJS on the Phantombuster platform, your bot has access to injectable JS modules already present on the disk. No need to make an additional request to a CDN to load the most common modules!
For example:
await tab.inject('../injectables/jquery-3.0.0.min.js')