Chrome Extension: Block all uploads user attempts to make on web page

128 Views Asked by At

I'm trying to create an extension for business purposes that blocks users from uploading documents on websites. Most websites use a simple <input type="file"> which I can easily intercept by either deactivating it or removing that element. But other sites have a button that continues to allow a user to choose a file to upload even if the input tag is removed. It seems like those sites control that button with JavaScript.

I have tried blocking the upload functionality on those sites by modifying the HTTP request that is called when the upload is submitted. My issue is figuring out when the HTTP request is trying to upload a file. Currently, I am using declarativeNetRequest API to change the HTTP Request header and setting all content-types to application/json; charset=utf-8. This helps prevent certain websites like Monster and Dice from uploading files as it doesn't expect the charset=utf-8 to be there on upload. At the same time, this is a bad solution as I am modifying every single request on the site to have that content-type. Also, maybe some websites don't use application/json at all.

Question: Am I able to completely disable the window that allows the user to choose a file using Chrome extensions API? Is there a more distinguished way of figuring out when a user is trying to upload a file via HTTP Request headers other than content-type?

If any more info is needed, I'm happy to provide it.

Thank you

0

There are 0 best solutions below