Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

98
Vistas
Can this simple Firefox extension be turned into a Greasemonkey script?

I have this Firefox extension that someone made for me. It prevents websites from opening download boxes and redirects and stuff like that. It works very well. It will prevent some websites from opening completely or working properly, but for my needs it works great.

Can this be turned into a Greasemonkey script, or it can only work as an extension?

main.js

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

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

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

manifest.json

    {
  "manifest_version": 2,
  "name": "mime-type-cancel",
  "version": "1.0",
  "permissions": [
    "webRequest",
    "webRequestBlocking",
    "<all_urls>"
  ],
  "background": {
    "scripts": [
      "main.js"
    ]
  }
}

Thanks

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The quick answer is, no.

Userscripts run in page context and they don't have access to Headers (e.g. request.responseHeaders) which happen before a page starts to load.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda