0

i want to build a chrome extension, download some file one by one, so i need pair the download file and the tabid that fire the download.

chrome.webRequest.onBeforeRequest.addListener(function (e) {
    log("onBeforeRequest:", JSON.stringify(e));
}, { urls: ["<all_urls>"] }, []);

use this code i can get the url, but can't get the tabid. the tabid is -1 allways, then, how can i get the correct tabid or how can i pair the download and the tabid?

fyi, i can't get <a> or href, i just mock click() event one by one.

defend orca
  • 617
  • 7
  • 17
  • 1
    This is a limitation of the API so you'll have to find a workaround. – wOxxOm Apr 22 '20 at 13:25
  • @wOxxOm, so how can i do it? – defend orca Apr 22 '20 at 14:58
  • 1
    I guess you'll have to intercept everything that may cause a download in your content script. – wOxxOm Apr 22 '20 at 15:03
  • @wOxxOm my contentscript make click(), and then download a file, but, from background, i can not make sure one download is fired by my contentscript. my target is just make the download one by one, because if i click them all at one time, only the last one will be download. – defend orca Apr 22 '20 at 15:42
  • @wOxxOm so i know that my click make the download, but when user click multi time my extension on different web page, i can not distinguish that, although i can intercept everything that cause a download. can you give me a idea? – defend orca Apr 23 '20 at 14:29
  • 1
    It depends on how exactly that page starts the download. My idea was to use a standard DOM method like an event listener or intercept something used by the site in [page context](/a/9517879). – wOxxOm Apr 23 '20 at 14:37
  • @wOxxOm, let me think about it, we add an right event listener, and know onepage download a file, but wen user download a lot of files from many pages, how can i know witch download is relate with witch page? or you mean by url? if by url, the question is how can i get a ajax download url? – defend orca Apr 24 '20 at 03:15
  • 1
    Example: [Chrome extension to read HTTP response](https://stackoverflow.com/a/48134114) – wOxxOm Apr 24 '20 at 04:01
  • @wOxxOm thank you very much. i will learn it. :) – defend orca Apr 24 '20 at 06:22

0 Answers0