Firefox - prevent Launch Application popup

Scorpion Ghost

Elite Member
Executive VIP
Jr. VIP
Joined
Mar 22, 2013
Messages
9,143
Reaction score
10,489
I want to prevent the "Launch Application" popup boxes from appearing in Firefox.

lau.PNG


The one in the image is for "webcal" links. But I also get ones for Spotify and others. Sometimes I visit sites and these just pop up out of nowhere. I want to completely prevent these from appearing.

I actually think I have the solution already in a Firefox extension I have, but I'm not sure. I have this:

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'
  ]
);

That was given to me by @sockpuppet a while ago here - https://www.blackhatworld.com/seo/g...-firefox-download-dialog-popup.1183643/page-2

And that code works to block any "Download boxes" from appearing. But these "Launch Application" boxes still appear, and I'd like to block them completely. I'm thinking adding or removing some code here would do it:

JavaScript:
  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;
  if (header.value.startsWith('application/x-javascript')) return false;

But I'm not sure what to do. Anyone knows? @Gogol
 
Okay I think I fixed it by removing this bit from the code:

JavaScript:
  if (header.value.startsWith('application/x-javascript')) return false;

I guess that now gets blocked also, and that blocks these popups.

I will say, after some testing, it seems I was only getting these specific popups on browsers where I use the iPhone useragent. I wasn't getting it on the others.

Oh well, I consider it solved. We'll see if it really is in a day or two :D
 
Not that I know how to solve it, but.... in this case, you could actually debug the value before the popup happens.. by doing

alert(header.value)

Then depending on what the value is, you could add another if block. But it looks like you solved it already, so.. congo :D
 
Back
Top