Search code examples
javascriptgetjson

"Insufficient resources error" when making repeated ajax requests from Chrome console


I have this javascript code that is meant to run inside the google chrome console. It constantly checks a json formatted response. If anywhere in the response BestPrice equals max_price then it will purchase it using some API. The problem I am having is about 10 seconds after running it I get 'ERR_INSUFFICIENT_RESOURCES'.

I suppose it is from too many requests? I need it to loop through as fast as possible, so if it can't be instant, is there a certain request limit?

Code:

function snipebot(page, max_page, max_price){
    $.getJSON('http://www.roblox.com/catalog/json?browse.aspx?Subcategory=2&Keyword=&CurrencyType=0&pxMin=0&pxMax=0&SortType=2&SortAggregation=0&SortCurrency=0&LegendExpanded=true&Category=2&PageNumber=' + page, function(data){
        $.each(data, function(index, item){
            if (item['BestPrice'] <= max_price){
                $.get('http://www.roblox.com/Item.aspx?id=' + item['AssetId'], function(data){
                    var purchaseData = $($(data).find(".PurchaseButton")[0]).data();
                    if (purchaseData['expectedPrice'] <= item['BestPrice']){
                        $.post('/API/Item.ashx?rqtype=purchase&productID=' + purchaseData['productId'] + '&expectedCurrency=1&expectedPrice=' + purchaseData['expectedPrice'] + '&expectedSellerId=' + purchaseData['expectedSellerId'] + '&userAssetID=' + purchaseData['userassetId'], function(){
                            console.log('[' + item['BestPrice'] + '] @' + new Date().toTimeString())    
                        });
                    } else {
                        console.log("Detected purchase.");
                    }
                });
            };
            setTimeout(function(){
                snipebot(page + 1 > max_page ? 1 : page + 1, max_page, max_price);
            },100);
            console.log("!checked");
        });
    });
};
snipebot(1, 4, 50);

Solution

  • When you call snipebot, it makes a request, and looking at the URL you're using, it gets an array back. Then for each item in the array, you are spawning another snipebot call. Each of those calls would in turn spawn more snipebot calls and so on. So, yeah, the ERR_INSUFFICIENT_RESOURCES error isn't really surprising.