How to download a file using pure javascript?

I’m trying to make a code in pure javascript (an extension for browser) who be capable to download a file to the source code folder.

Using NPM, the code must be like that:

var http = require('http'),                                                
    Stream = require('stream').Transform,                                  
    fs = require('fs');                                                    

var url = 'http://www.google.com/images/srpr/logo11w.png';                    

http.request(url, function(response) {                                        
  var data = new Stream();                                                    

  response.on('data', function(chunk) {                                       
    data.push(chunk);                                                         
  });                                                                         

  response.on('end', function() {                                             
    fs.writeFileSync('image.png', data.read());                               
  });                                                                         
}).end();

But I canĀ“t use the npm in an extension, so, I need to use pure javascript to make that process, and I didn’t find anything on the web about this.