How to download Bitcoin block headers from Blockchain.info and save to file?
You can download the blockchain headers from here. The data is binary packed, but can be deserialized easily enough. You seem to be trying to solo mine, which is a bad idea at the best of times, let alone with JavaScript. You also seems to be trying to build a SPV client. An easier way would just be to use https://blockchain.info/latestblock to get the lastblock hash and use that.