Chrome扩展程序:Javascript可以拦截文件下载并解析数据 [英] Chrome Extension: Can Javascript intercept a file download and parse the data

查看:650
本文介绍了Chrome扩展程序:Javascript可以拦截文件下载并解析数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写Chrome扩展程序来自动执行我的一项日常任务,其中一部分任务是下载.csv文件并操作数据。作为自动化的一部分,我想用Javascript抓住文件,并让脚本对它进行操作。



问题是,使用XMLHttpRequest获取这个文件将是一场噩梦,因为它们发送一堆独特的ID来验证用户,这将是一个噩梦,找出他们来自哪里。



我可以轻松点击按钮使用JavaScript启动文件下载,但有没有一种方法,JavaScript可以拦截此请求并解析CSV?我想如果它不可能与普通的JavaScript我可能能够做到这一点与HTML5的文件API?

你可能会尝试使用 webRequest.onBeforeRequest API。当您想要下载请求时,您可以使用此方法取消它,获取正在使用的完整URL并使用JavaScript发出相同请求。


I'm writing a Chrome Extension to automate one of my daily tasks, part of the task is downloading a .csv file and manipulating the data. As part of the automation I want to grab the file with Javascript and make the script manipulate it.

The problem is grabbing this file with an XMLHttpRequest would be a nightmare because they send heaps of unique IDs to verify the user and it'd be a nightmare to work out where they come from.

I can easily click the button using javascript which starts the file download, but is there a way that javascript can intercept this request and parse the CSV? I'm thinking if its not possible with plain javascript I might be able to do it with the HTML5 file API?

解决方案

You might try using the webRequest.onBeforeRequest API. When the download request is you want is made you can cancel it with this method, get the complete URL being used, and make that same request from JavaScript.

这篇关于Chrome扩展程序:Javascript可以拦截文件下载并解析数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆