Ali Tor Ali Tor - 1 year ago 125
Javascript Question

How to cancel a chrome download before it starts and get the download url?

I want to integrate my C# download manager using a Chrome Extension and I am new in extension development.

So I need to detect when a download request is sent in chrome. Then I need to get the url and pass it to my program to download. I tried it but couldn't get any response.

My code:


"manifest_version": 2,

"name": "ADM",
"description": "This extension shows a Google Image search result for the current page",
"version": "1.0",

"browser_action": {
"default_icon": "icon.png"
"permissions": [

"content_scripts": [{
"matches" : ["http://*/*", "https://*/*"],
"js" : ["myscript.js"]


chrome.downloads.onDeterminingFilename.addListener(function (item) {

As I said, this code didn't cancel the download and show the url for test. How can I do it?

Answer Source

You are trying to access privileged Chrome apis from a content script, which is not permitted for security reasons. You need to move your code to an event page.

"background": { "scripts": ["myscript.js"], "persistent": false }

Also, read the architecture overview:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download