1

I'm working on a Safari extension and I want it to be notified before a download window appears. Since there is no event for download I guess I have to process the response headers, but I was not able to access them either. I was wondering what is the proper way to do this?

2
  • Is this an extension what will run on /any/ page? Or on specific ones? If the second, you could add onclick event to the download link. Sep 14, 2012 at 22:34
  • It's going to run on any page.
    – Abcd Efg
    Sep 14, 2012 at 22:39

1 Answer 1

0

From my limited experience tinkering with Safari and Chrome extensions, I believe you need to listen for a page to fire off either (or both) of these events: beforeLoad and beforeNavigate. Dealing with beforeLoad is described very well in the section on blocking content, and beforeNavigate is described here.

With either of those events, you'd need to determine if the URL in question is a download or a normal web file. I suspect you could do a fast check for common download filetypes such as .zip, .mp3, and others, but the only way to be certain might be to perform your own short HTTP request and analyze the response, as you noted in your question.

Caution: There's no API for detecting downloads because extensions have almost no power over the files on a user's computer anyway. This means that downloads should typically be outside the scope of extensions, and the responsibility of platform-native apps instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.