Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

97
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!