最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I save an array object to file at run-time by chrome debug tools? - Stack Overflow

programmeradmin0浏览0评论

I would like to extract an array object at run-time. For example:

var myarr = [1,2,3,4,5];

How can I save myarr at location /home/username/myarr.txt in Chrome DevTools?

I would like to extract an array object at run-time. For example:

var myarr = [1,2,3,4,5];

How can I save myarr at location /home/username/myarr.txt in Chrome DevTools?

Share Improve this question asked Mar 26, 2017 at 8:11 khakha 3534 silver badges18 bronze badges 1
  • Chrome doesn't allow writing to an arbitrary path in the real file system. Chrome extensions may use chrome.downloads API to save the files to paths inside the downloads directory and that's about all. – woxxom Commented Mar 26, 2017 at 9:18
Add a ment  | 

1 Answer 1

Reset to default 15

You can't download to a specific location, however you can download this file to your Chrome downloads path (where all your files are download in to). Try this (it is working for me):

var arr = [ 1, 2, 3 ];
var a = document.createElement('a');
var file = new Blob([ arr.toString() ], { type: 'text/plain' });

a.href = URL.createObjectURL(file);
a.download = 'bla';
a.click();

It should download a file named 'bla' containing the array values.

发布评论

评论列表(0)

  1. 暂无评论