node js giving "RangeError: Maximum call stack size exceeded" on VPS machine - node.js

I am using Phantom JS to load a third party URL. Then there is an node+express server with "phantom" module, which is returning back the htmls from Phantom JS.
The code works perfect in my mac, but when I try to run it in VPS, node is giving
RangeError: Maximum call stack size exceeded
function scrape(url, func){
var phantom = require('phantom');
phantom.create('--load-images=no', function(ph){
return ph.createPage(function(page){
page.set('settings.loadImages', false) ;
return page.open(url, function(status){
//page.injectJs('http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', function() {
return page.evaluate((function(){
var scripts = document.getElementsByTagName('script'),
links = document.getElementsByTagName('link'),
images = document.getElementsByTagName('img'),
objects = document.getElementsByTagName('object');
for(i in objects){
if((obj = objects[i]) && obj.data){
if(obj.getAttribute('data') != obj.data){
obj.setAttribute('data', obj.data);
var params = obj.getElementsByTagName('param');
for(var j in params){
if((par = params[j]) && par.value){
console.log(par.name);
if(par.getAttribute('value') != par.value){
par.setAttribute('value', par.value);
}
if(par.name == "allowscriptaccess" ){
par.setAttribute('value', "always");
par.value = "always";
}
}
}
}
}
}
for(i in scripts){
if((script = scripts[i]) && script.src){
if(script.getAttribute('src') != script.src){
script.setAttribute('src', script.src);
}
}
}
for(i in links){
if((link = links[i]) && link.href ){
if(link.getAttribute('href') != link.href){
link.setAttribute('href', link.href);
}
}
}
for(i in images){
if((image = images[i]) && image.src){
if(image.getAttribute('src') != image.src){
image.setAttribute('src', image.src);
}
}
}
var baseTag = document.getElementsByTagName('base');
if(baseTag.length == 0){
var baseTag = '<base id="test" href="'+ document.domain +'" />';
var head = document.getElementsByTagName('head');
head[0].innerHTML = baseTag + head[0].innerHTML;
}
return document.getElementsByTagName('html')[0].outerHTML;
}), function(result){
ph.exit(); (func)(result);
});
//});
});
});
});
}
exports.scrape = scrape;

Related

Cannot read property '706142720527171634' of undefined. discord music bot crashes

My bot has a skip and stop commands it gives this error when I try that command
Cannot read property '706142720527171634' of undefined
I also re-wrote the code,
These are the two commands' codes
if(msg.content === 'r!' + 'skip'){
server.dispatcher = connection.play(ytdl(server.queue[0],{filter: "audioonly"}));
var server = servers[msg.guild.id];
if (server.dispatcher) server.dispatcher.end();
}
if(msg.content === 'r!' + 'stop'){
var server = server[msg.guild.id];
if(msg.guild.voice.connection){
for(var i = server.queue.length -1; i >=0; i--){
server.queue.splice(i, 1);
}
Here, you used server instead of servers: server[msg.guild.id];.
The following should work:
if(msg.content === 'r!' + 'skip'){
server.dispatcher = connection.play(ytdl(server.queue[0],{filter: "audioonly"}));
var server = servers[msg.guild.id];
if (server.dispatcher) server.dispatcher.end();
}
if(msg.content === 'r!' + 'stop'){
var server = servers[msg.guild.id];
if(msg.guild.voice.connection){
for(var i = server.queue.length -1; i >=0; i--){
server.queue.splice(i, 1);
}

Instagram Auto-Like JavaScript BOT

This code brings back an error of
Uncaught TypeError: Cannot read property 'innerHTML' of null
at doLike (<anonymous>:20:21)
at <anonymous>:35:1
doLike # VM1269:20
(anonymous) # VM1269:35
It has worked in the past, I got it from this website : https://blog.joeldare.com/simple-instagram-like-bot/
function getHeartElement() {
var knownHeartElementNames = ["coreSpriteHeartOpen", "coreSpriteLikeHeartOpen"];
var i = 0;
// Loop through the known heart elements until one works
for (i = 0; i < knownHeartElementNames.length; i++) {
var heartElement = document.querySelector("." + knownHeartElementNames[i]);
if (heartElement != undefined) {
break;
}
}
return heartElement;
}
function doLike() {
var likeMax = 100;
var likeElement = getHeartElement();
var nextElement = document.querySelector(".coreSpriteRightPaginationArrow");
likeCount++;
var nextTime = Math.random() * (14000 - 4000) + 4000;
if (likeElement.innerHTML.match("Unlike") == null) {
likeElement.click();
console.log(likeCount + " - liked");
} else {
console.log(likeCount + " - skipped");
}
setTimeout(function() {nextElement.click();}, 1000);
if (likeCount < likeMax) {
setTimeout(doLike, nextTime);
} else {
console.log("Nice! Time for a break.");
}
}
var likeCount = 0;
doLike();
You may want to use a tool such a Keygram - https://www.thekeygram.com
It works really well for me to gain followers

SP.NavigationNode.get_isVisible() broken?

I need to read the "Top Nav", the "Children Nodes" and check if each node is visible.
I am using JSOM to accomplish this. Everything is working fine except for the get_isVisible() function. It always returns true. MSDN: http://msdn.microsoft.com/en-us/library/office/jj246297.aspx
I am on a publishing site in 2013 and I know some of the items are hidden. (My web and context are defined outside of this snippet)
var visParents = [], visChildren = [];
var topNodes = web.get_navigation().get_topNavigationBar();
context.load(topNodes);
context.executeQueryAsync(onQuerySucceeded, onQueryFailed)
function onQuerySucceeded() {
var nodeInfo = '';
var nodeEnumerator = topNodes.getEnumerator();
while (nodeEnumerator.moveNext()) {
var node = nodeEnumerator.get_current();
nodeInfo += node.get_title() + '\n';
if (node.get_isVisible())
visParents.push(node);
}
console.log("Current nodes: \n\n" + nodeInfo);
console.log("Visible Parents", visParents)
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
It is a known issue, it seems that SP.NavigationNode.isVisible property does not correspond to the property that indicates whether navigation node is hidden or shown.
Please refer "Hidden" property of SPNavigationNode for a details
The following function demonstrates how to retrieve hidden node Urls:
function getGlobalNavigationExcludedUrls(Success,Error)
{
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var subwebs = web.get_webs();
var pagesList = web.get_lists().getByTitle("Pages");
var pageItems = pagesList.getItems(SP.CamlQuery.createAllItemsQuery());
var allProperties = web.get_allProperties();
context.load(web);
context.load(subwebs);
context.load(allProperties);
context.load(pageItems);
context.executeQueryAsync(
function() {
var excludedIds = allProperties.get_item('__GlobalNavigationExcludes').split(';');
var exludedUrls = [];
for (var i = 0; i < excludedIds.length - 1; i++ )
{
for (var j = 0; j < subwebs.get_count(); j++ )
{
var subweb = subwebs.getItemAtIndex(j);
if(subweb.get_id().toString() == excludedIds[i]){
exludedUrls.push(subweb.get_serverRelativeUrl());
break;
}
}
for (var j = 0; j < pageItems.get_count(); j++ )
{
var pageItem = pageItems.getItemAtIndex(j);
if(pageItem.get_item('UniqueId').toString() == excludedIds[i]){
exludedUrls.push(web.get_serverRelativeUrl() + pageItem.get_item('FileRef'));
break;
}
}
}
Success(exludedUrls);
},
Error
);
}
//Usage: print excluded nodes Urls
getGlobalNavigationExcludedUrls(function(excludedNodeUrls){
for (var j = 0; j < excludedNodeUrls.length; j++ )
{
console.log(excludedNodeUrls[j]);
}
},
function(sender,args){
console.log(args.get_message());
});

Node is not launching

I'm desperately trying to make node.js work again on Ubuntu 12.04 LTS.
I installed it before 2-3 weeks ago and everything went fine, I used it daily for that period of time.
But today, suddenly it just wouldn't work anymore. The way it bugs is really strange :
node -v works and returns v0.8.2
the node command works too, I can access the console and do a console.log
but when I use node with a file like this node server.js, Ubuntu just goes to a new line :
kollektiv#kollektiv-PC:~/node-projects$ node server.js
kollektiv#kollektiv-PC:~/node-projects$
I already reinstalled Ubuntu this evening but I get the same result.
I also did multiple apt-get upgrade and apt-get update in case some node.js dependencies would be out of date.
The way I installed node.js is by compiling the source following this tutorial : --> Compiling Node.js from source on Ubuntu 10.24 - shapeshed
I even did a chmod 777 server.js on the server file just to be sure but that didn't change anything either.
Thank you a lot in advance for your help !
EDIT : Content of server.js
var net = require('net'),
server = net.createServer();
var crypto = require('crypto'),
shasum = crypto.createHash('sha256');
var alpha = [],
i = 0,
cle = '';
while(i < 256) {
alpha.push(String.fromCharCode(i));
i++;
}
// CRYPTAGE -- START --
function cryptProcess(cle, txt) {
var k = txt.length,
j = k / cle.length,
cledeBase = cle,
txtc = '',
i = 1;
while(i < j) {
cle = cle + cledeBase;
i++;
}
function crypt(cleu, letr) {
//if(alpha.indexOf(letr) == -1) return "§";
var biIndex = alpha.indexOf(letr) + alpha.indexOf(cleu), x;
sumIndex = biIndex - alpha.length;
x = sumIndex >= 0 ? alpha[sumIndex] : alpha[biIndex];
return x;
}
while(k--) {
txtc = crypt(cle[k], txt[k]) + txtc;
}
return txtc;
}
function decryptProcess(cle, txtc) {
var k = txtc.length,
j = k / cle.length,
cledeBase = cle,
txt = '',
i = 1;
while(i < j) {
cle = cle + cledeBase;
i++;
}
txt = '';
function decrypt(cleu, letc) {
//if(alpha.indexOf(letc) == -1) return "§";
var biIndex = letc - alpha.indexOf(cleu), x;
x = biIndex >= 0 ? alpha[biIndex] : alpha[biIndex + alphabet.length];
return x;
}
while(k--) {
txt = decrypt(cle[k], txtc[k]) + txt;
}
return txt;
}
// CRYPTAGE -- END --
server.on('connection', function(client) {
var connecOne = 0;
function talk(data) {
var msg = data.toString('utf8');
var msgEnc = cryptProcess(cle, msg);
client.write(msgEnc);
console.log(msg + '\nsend as\n' + msgEnc);
}
client.once('data', function(data) {
function triHandShake() {
}
});
client.on('data', function(data) {
var msg = data.toString('utf8');
if(connecOne === 0) {
connectionOne(msg);
connecOne++;
}
else if(connecOne === 1) {
// Check for paragraph symbol
//authentification with cookie as cle
}
var msgDec = decryptProcess(cle, msg);
console.log(msgDec + '\nreiceved as\n' + msgDec);
});
client.on('end', function() {
connecOne = 0;
});
});
You need to call server.listen to listen for connections and start the process as expected.
server.listen(8124, function() { //'listening' listener
console.log('server bound');
});

Opening tabs in Chrome news reader extension

I'm trying to create a simple chrome extension using the following google RSS reader sample,
http://code.google.com/chrome/extensions/samples.html#597015d3bcce3da693b02314afd607bec4f55291
I can add links in the pop-up window that open tabs, but not from the feeds themselves.
Looping through the items in the feed, grabbing title tags and link tags, I want the title to link the the appropriate sites
var entries = doc.getElementsByTagName('item');
var count = Math.min(entries.length, maxFeedItems);
for (var i = 0; i < count; i++) {
item = entries.item(i);
// Grab the title for the feed item.
var itemTitle = item.getElementsByTagName('title')[0];
if (itemTitle) {
itemTitle = itemTitle.textContent;
} else {
itemTitle = "Unknown title";
}
// Grab the link for this feed item
var itemLink = item.getElementsByTagName('link')[0];
if (itemLink) {
itemLink = itemLink.textContent;
} else {
itemLink = "Unknown link";
}
var title = document.createElement("a");
title.className = "item_title";
title.innerText = itemTitle; //display title in iframe
title.addEventListener("click", titleLink); // should open link when clicking on title, but does not.
}
// -------------------------------------------------------------------
// Show |url| in a new tab.
function showUrl(url) {
// Only allow http and https URLs.
if (url.indexOf("http:") != 0 && url.indexOf("https:") != 0) {
return;
}
chrome.tabs.create({url: url});
}
function moreStories(event) {
showUrl(moreStoriesUrl);
}
function titleLink(event) {
showUrl(itemLink);
}
Any thoughts on why this is not working.
If I replace title.addEventListener("click", titleLink); with title.addEventListener("click", moreStories); each title will link to moreStories, I cannot get each title to link to itemLink.
Thanks
Its a bit hard to answer your question without the whole code, but Ill give it a shot ;)
First up, titleLink() isnt going to work because itemLink isnt known. When you create title (the link) you should of attached it to that...say title.href=itemLink then in tiltleLinks you could access that href with showUrl(event.currentTarget.href)
Also did you fix the error in that example?...if not then change frameLoaded to....
function frameLoaded() {
var links = document.getElementsByTagName("A");
for (i = 0; i < links.length; i++) {
var clssName = links[i].className;
if (clssName != "item_title" && clssName != "open_box") {
links[i].addEventListener("click", showStory);
}
}
window.addEventListener("message", messageHandler);
}
If you still have probs could you attach the whole code so I can see what your doing and Ill give you a hand.
Thank you very much for your help.
code title.href=itemLink and code showUrl(event.currentTarget.href) was exactly what I needed.
For completeness, here is the full code,
<script id="iframe_script">
function reportHeight() {
var msg = JSON.stringify({type:"size", size:document.body.offsetHeight});
parent.postMessage(msg, "*");
}
function frameLoaded() {
var links = document.getElementsByTagName("A");
for (i = 0; i < links.length; i++) {
var class = links[i].className;
if (class != "item_title" && class != "open_box") {
links[i].addEventListener("click", showStory);
}
}
window.addEventListener("message", messageHandler);
}
function showStory(event) {
var href = event.currentTarget.href;
parent.postMessage(JSON.stringify({type:"show", url:href}), "*");
event.preventDefault();
}
function messageHandler(event) {
reportHeight();
}
</script>
<script>
// Feed URL.
var feedUrl = 'http://localhost/newsfeed.xml';
// The XMLHttpRequest object that tries to load and parse the feed.
var req;
function main() {
req = new XMLHttpRequest();
req.onload = handleResponse;
req.onerror = handleError;
req.open("GET", feedUrl, true);
req.send(null);
}
// Handles feed parsing errors.
function handleFeedParsingFailed(error) {
var feed = document.getElementById("feed");
feed.className = "error";
feed.innerText = "Error: " + error;
}
// Handles errors during the XMLHttpRequest.
function handleError() {
handleFeedParsingFailed('Failed to fetch RSS feed.');
}
// Handles parsing the feed data we got back from XMLHttpRequest.
function handleResponse() {
var doc = req.responseXML;
if (!doc) {
handleFeedParsingFailed("Not a valid feed.");
return;
}
buildPreview(doc);
}
// The maximum number of feed items to show in the preview.
var maxFeedItems = 10;
// Where the more stories link should navigate to.
var moreStoriesUrl;
function buildPreview(doc) {
// Get the link to the feed source.
var link = doc.getElementsByTagName("link");
var parentTag = link[0].parentNode.tagName;
if (parentTag != "item" && parentTag != "entry") {
moreStoriesUrl = link[0].textContent;
}
// Setup the title image.
var images = doc.getElementsByTagName("image");
var titleImg;
if (images.length != 0) {
var urls = images[0].getElementsByTagName("url");
if (urls.length != 0) {
titleImg = urls[0].textContent;
}
}
var img = document.getElementById("title");
// Listen for mouse and key events
if (titleImg) {
img.src = titleImg;
if (moreStoriesUrl) {
document.getElementById("title_a").addEventListener("click",moreStories);
document.getElementById("title_a").addEventListener("keydown",
function(event) {
if (event.keyCode == 13) {
moreStories(event);
}});
}
} else {
img.style.display = "none";
}
// Construct the iframe's HTML.
var iframe_src = "<!doctype html><html><head><script>" +
document.getElementById("iframe_script").textContent + "<" +
"/script></head><body onload='frameLoaded();' " +
"style='padding:0px;margin:0px;'>";
var feed = document.getElementById("feed");
// Set ARIA role indicating the feed element has a tree structure
feed.setAttribute("role", "tree");
var entries = doc.getElementsByTagName('item');
var count = Math.min(entries.length, maxFeedItems);
for (var i = 0; i < count; i++) {
item = entries.item(i);
// Grab the title for the feed item.
var itemTitle = item.getElementsByTagName('title')[0];
if (itemTitle) {
itemTitle = itemTitle.textContent;
} else {
itemTitle = "Unknown title";
}
// Grab the link for the feed item.
var itemLink = item.getElementsByTagName('link')[0];
if (itemLink) {
itemLink = itemLink.textContent;
} else {
itemLink = "Unknown link";
}
var item = document.createElement("div");
var title = document.createElement("a");
title.innerText = itemTitle; //display title in iframe
title.href=itemLink;
title.addEventListener("click", titleLink);
item.appendChild(title);
feed.appendChild(item);
}
if (moreStoriesUrl) {
var more = document.createElement("a");
more.className = "more";
more.innerText = "***Site Main Page*** \u00BB";
more.tabIndex = 0;
more.addEventListener("click", moreStories);
more.addEventListener("keydown", function(event) {
if (event.keyCode == 13) {
moreStories(event);
}});
feed.appendChild(more);
}
}
// -------------------------------------------------------------------
// Show |url| in a new tab.
function showUrl(url) {
// Only allow http and https URLs.
if (url.indexOf("http:") != 0 && url.indexOf("https:") != 0) {
return;
}
chrome.tabs.create({url: url});
}
// -------------------------------------------------------------------
function moreStories(event) {
showUrl(moreStoriesUrl);
}
function titleLink(event) {
showUrl(event.currentTarget.href);
}
function keyHandlerShowDesc(event) {
// Display content under heading when spacebar or right-arrow pressed
// Hide content when spacebar pressed again or left-arrow pressed
// Move to next heading when down-arrow pressed
// Move to previous heading when up-arrow pressed
if (event.keyCode == 32) {
showDesc(event);
} else if ((this.parentNode.className == "item opened") &&
(event.keyCode == 37)) {
showDesc(event);
} else if ((this.parentNode.className == "item") && (event.keyCode == 39)) {
showDesc(event);
} else if (event.keyCode == 40) {
if (this.parentNode.nextSibling) {
this.parentNode.nextSibling.children[1].focus();
}
} else if (event.keyCode == 38) {
if (this.parentNode.previousSibling) {
this.parentNode.previousSibling.children[1].focus();
}
}
}
function showDesc(event) {
var item = event.currentTarget.parentNode;
var items = document.getElementsByClassName("item");
for (var i = 0; i < items.length; i++) {
var iframe = items[i].getElementsByClassName("item_desc")[0];
if (items[i] == item && items[i].className == "item") {
items[i].className = "item opened";
iframe.contentWindow.postMessage("reportHeight", "*");
// Set the ARIA state indicating the tree item is currently expanded.
items[i].getElementsByClassName("item_title")[0].
setAttribute("aria-expanded", "true");
iframe.tabIndex = 0;
} else {
items[i].className = "item";
iframe.style.height = "0px";
// Set the ARIA state indicating the tree item is currently collapsed.
items[i].getElementsByClassName("item_title")[0].
setAttribute("aria-expanded", "false");
iframe.tabIndex = -1;
}
}
}
function iframeMessageHandler(e) {
// Only listen to messages from one of our own iframes.
var iframes = document.getElementsByTagName("IFRAME");
for (var i = 0; i < iframes.length; i++) {
if (iframes[i].contentWindow == e.source) {
var msg = JSON.parse(e.data);
if (msg) {
if (msg.type == "size") {
iframes[i].style.height = msg.size + "px";
}
else if (msg.type == "show") {
var url = msg.url;
if (url.indexOf("http://localhost/index.html") == 0) {
// If the URL is a redirect URL, strip of the destination and go to
// that directly. This is necessary because the Google news
// redirector blocks use of the redirects in this case.
var index = url.indexOf("&url=");
if (index >= 0) {
url = url.substring(index + 5);
index = url.indexOf("&");
if (index >= 0)
url = url.substring(0, index);
}
}
showUrl(url);
}
}
return;
}
}
}
window.addEventListener("message", iframeMessageHandler);
</script>
Thanks again for the help.
-Mike

Resources