Greasemonkey script to cancel Firefox download dialog popup

Those browser.helpers.neverask should be set to 1, not mp3 lol. The values are Boolean there, 0 for false, 1 for true, empty if not defined.
So, the browser says "I should never ask about downloads?"
And @Scorpion Ghost says "audio/mpeg" :D
 
Those browser.helpers.neverask should be set to 1, not mp3 lol. The values are Boolean there, 0 for false, 1 for true, empty if not defined.
So, the browser says "I should never ask about downloads?"
And @Scorpion Ghost says "audio/mpeg" :D

Of course I tried those man. That option is empty by default.

But I just tried it again just in case. Tried it on empty, tried it on 0, tried it on 1, tried it on 2. The download prompt appeared on each.

Link used for testing because this site/page tries to get you to download a file - https://myaddictive.com/telecharger/prisca-ly-mister-h-a-vida.html

So, no :)
 
browser.download.panel.shown set to false?

Just a suggestion, can't test right now, I have that portable Firefox that you use on my laptop at home.
 
browser.download.panel.shown set to false?

Just a suggestion, can't test right now, I have that portable Firefox that you use on my laptop at home.

Yes it's set to false, by default, I didn't make any changes to it.

What you thinking?
 
I will test later and if I come up with something, I'll let you know
 
I will test later and if I come up with something, I'll let you know

Okay man, thanks.

I'd much prefer a "native" Firefox solution over the Autohotkey solution. So if you figure it out let me know.
 
made an extension to cancel the request for all but some whitelisted content types
put both files in a directory and load it as a temporary addon


manifest.json
Code:
{
  "manifest_version": 2,
  "name": "mime-type-cancel",
  "version": "1.0",
  "permissions": [
    "webRequest",
    "webRequestBlocking",
    "<all_urls>"
  ],
  "background": {
    "scripts": [
      "main.js"
    ]
  }
}
main.js
Code:
'use strict';

const mimeTypeMatch = function (header) {
  if (header.name === undefined) {
    return false;
  }
  if (header.name.toLowerCase() != 'content-type') {
    return false;
  }
  if (header.value.startsWith('image')) return false;
  if (header.value.startsWith('text')) return false;
  if (header.value.startsWith('font')) return false;
  if (header.value.startsWith('application/json')) return false;
  if (header.value.startsWith('application/javascript')) return false;

  console.log('cancel content type');
  console.log(header);
  return true;
};

const headersReceived = function (request) {
  return new Promise((resolve) => {
    let filter = false;

    request.responseHeaders.forEach(h => {
      if (mimeTypeMatch(h)) {
        filter = true;
        return;
      }
      if (h.name.toLowerCase() === 'content-disposition') {
        filter = true;
        return;
      }
    });

    if (filter) {
      resolve({
        cancel:true
      });
      return;
    }

    resolve();
  });
};

browser.webRequest.onHeadersReceived.addListener(
  headersReceived,
  {
    urls: ['<all_urls>']
  },
  [
    'blocking',
    'responseHeaders'
  ]
);
 
made an extension to cancel the request for all but some whitelisted content types
put both files in a directory and load it as a temporary addon


manifest.json
Code:
{
  "manifest_version": 2,
  "name": "mime-type-cancel",
  "version": "1.0",
  "permissions": [
    "webRequest",
    "webRequestBlocking",
    "<all_urls>"
  ],
  "background": {
    "scripts": [
      "main.js"
    ]
  }
}
main.js
Code:
'use strict';

const mimeTypeMatch = function (header) {
  if (header.name === undefined) {
    return false;
  }
  if (header.name.toLowerCase() != 'content-type') {
    return false;
  }
  if (header.value.startsWith('image')) return false;
  if (header.value.startsWith('text')) return false;
  if (header.value.startsWith('font')) return false;
  if (header.value.startsWith('application/json')) return false;
  if (header.value.startsWith('application/javascript')) return false;

  console.log('cancel content type');
  console.log(header);
  return true;
};

const headersReceived = function (request) {
  return new Promise((resolve) => {
    let filter = false;

    request.responseHeaders.forEach(h => {
      if (mimeTypeMatch(h)) {
        filter = true;
        return;
      }
      if (h.name.toLowerCase() === 'content-disposition') {
        filter = true;
        return;
      }
    });

    if (filter) {
      resolve({
        cancel:true
      });
      return;
    }

    resolve();
  });
};

browser.webRequest.onHeadersReceived.addListener(
  headersReceived,
  {
    urls: ['<all_urls>']
  },
  [
    'blocking',
    'responseHeaders'
  ]
);

Woooooow duuuuude. It works! :cool:

337.gif


 
made an extension to cancel the request for all but some whitelisted content types
put both files in a directory and load it as a temporary addon


manifest.json
Code:
{
  "manifest_version": 2,
  "name": "mime-type-cancel",
  "version": "1.0",
  "permissions": [
    "webRequest",
    "webRequestBlocking",
    "<all_urls>"
  ],
  "background": {
    "scripts": [
      "main.js"
    ]
  }
}
main.js
Code:
'use strict';

const mimeTypeMatch = function (header) {
  if (header.name === undefined) {
    return false;
  }
  if (header.name.toLowerCase() != 'content-type') {
    return false;
  }
  if (header.value.startsWith('image')) return false;
  if (header.value.startsWith('text')) return false;
  if (header.value.startsWith('font')) return false;
  if (header.value.startsWith('application/json')) return false;
  if (header.value.startsWith('application/javascript')) return false;

  console.log('cancel content type');
  console.log(header);
  return true;
};

const headersReceived = function (request) {
  return new Promise((resolve) => {
    let filter = false;

    request.responseHeaders.forEach(h => {
      if (mimeTypeMatch(h)) {
        filter = true;
        return;
      }
      if (h.name.toLowerCase() === 'content-disposition') {
        filter = true;
        return;
      }
    });

    if (filter) {
      resolve({
        cancel:true
      });
      return;
    }

    resolve();
  });
};

browser.webRequest.onHeadersReceived.addListener(
  headersReceived,
  {
    urls: ['<all_urls>']
  },
  [
    'blocking',
    'responseHeaders'
  ]
);

Hey man,

So this is working wonderfully, thanks again.

But I have an issue with one website where something crucial doesn't function correctly if I have this installed.

Could I bother you to tell me how to add 1 website as an exception? Say Facebook.com* (so Facebook.com and * any urls stemming from that domain)

I'm pretty sure the edit would go here:

{
urls: ['<all_urls>']
},

But I have no idea how to do it. Could you?
 
this is untest but try this after the line
let filter = false;

Code:
if ( (['facebook.com','google.com']).find( u => {
  const uri = new URL(request.originUrl);
  return u === uri.hostname;
}) ) {
  resolve({});
  return;
}

or open the dev console on the site that doesn't work and look for lines like
Code:
cancel content type
<the blocked content type like application/json>
then in the mimeTypeMatch function add a line with this content type
if (header.value.startsWith('<the content type>')) return false;
 
this is untest but try this after the line
let filter = false;

Code:
if ( (['facebook.com','google.com']).find( u => {
  const uri = new URL(request.originUrl);
  return u === uri.hostname;
}) ) {
  resolve({});
  return;
}

or open the dev console on the site that doesn't work and look for lines like
Code:
cancel content type
<the blocked content type like application/json>
then in the mimeTypeMatch function add a line with this content type
if (header.value.startsWith('<the content type>')) return false;

Boss! I used the first thing you said, added an exception and it did the trick. Perfect man you're the best thank you :)
 
@sockpuppet you still around?

The stuff you made works great, I still use it :)

I was wondering, could this be made to work as a Greasemonkey script?
 
I'm curious if there are any devs on this forum who are familiar with the structure of XUL extensions in general, almost all the information online seems to be based on webextensionsAPI. Anyone here who made FF extensions prior to 2017?
 
I'm curious if there are any devs on this forum who are familiar with the structure of XUL extensions in general, almost all the information online seems to be based on webextensionsAPI. Anyone here who made FF extensions prior to 2017?

I'd like to know that too. I talked to a few people that deal with Firefox/Chrome extensions, and they all just make webextensions. I even had a guy who looked for resources on how to make a XUL extension and he basically told me:

no sr because i dont know how to create XUL/XPCOM extensions and also is a very long process just to make a build
also mostly domucomentation was removed
https://extensionworkshop.com/documentation/develop/porting-a-legacy-firefox-extension/

I also did a google search on making XUP extensions or turning webextensions into XUL, and I didn't really find any guides/tutorials that looked like I could follow through. Anyway not that much info about it out there, at least from the little search I did. I'm sure if I dig and dig, read books and attend 7 universities I could find the information, but fuck that :D
 
just came across this
https://addonconverter.fotokraina.com/Worth a shot, since SeaMonkey is also XUL/XPCOM

Good find.

I tried it for this extension in this post, but I got an error:

install.rdf not found in installer

The extension has a manifest.json, not install.rdf.

Worth a shot with any extension I guess. I bookmarked the link. Good find :)
 
Back
Top