infinitered / nsfwjs

NSFW detection on the client-side via TensorFlow.js
https://nsfwjs.com/
MIT License
7.94k stars 528 forks source link

Cannot run in browser extensions #558

Open isaackogan opened 2 years ago

isaackogan commented 2 years ago

Manifest V3 for chromium based browsers require extensions have no remote-executed code (unsafe-eval must be disabled), nsfwjs uses new Function() 9 separate times, making the library unusable, since loading a function from a String is considered unsafe-eval.

Is there a workaround, if anyone around her has used it with chromium-based apps? Would it be worth it for me to just fork & edit it myself?

Isaac

156c8b4394cbfbf13802182d0c9a84a9

GantMan commented 2 years ago

For an extension have you tried this fix? https://stackoverflow.com/questions/26242682/unsafe-eval-on-chrome-extension

For the changes you're proposing, what do those look like?

isaackogan commented 2 years ago

Those changes don't work. Unfortunately google is deprecating manifest v3, so unsafe-eval will not be a possible choice for chrome webstore developers come ~January 2022.

After doing a bit of looking around, I can't find the offending code in the source on this repo, which leads me to believe it's being created by the minifier?

https://unpkg.com/nsfwjs@2.3.0/dist/nsfwjs.min.js

Not sure what changes I'm proposing, but these are the recurring elements that make it unable to run in browser:

eval()
Function()     // typically new Function()
setTimeout()   // with non-callable argument
setInterval()  // with non-callable argument
setImmediate()
execScript()

I looked around and there are a plethora of Chrome apps using your library (It's a sick library, by the way), and they also will not be able to create new ones using it after Jan '22

image

GantMan commented 2 years ago

Thanks so much!!! I appreciate the kudos. @isaackogan - I could use your help right quick!

My guess is the issue is because my TypeScript is set to be supported as far back as ES5. https://github.com/infinitered/nsfwjs/blob/master/tsconfig.json#L10

Would you mind pulling the code down, and trying different targets (https://www.typescriptlang.org/tsconfig#target) to see if one of these will remove the offending code?

IF - that's the issue, I can release a second version on NPM that isn't as backwards compatible, but would work well on browser extensions.


Side note: How do you find a list of chrome apps that are using NSFWJS? I'd love to see that list!

0xturboblitz commented 2 years ago

I'm having the same issue. Does anyone have a solution ? Manifest v2 extension now cannot be added to the chrome extension store

isaackogan commented 2 years ago

Thanks so much!!! I appreciate the kudos. @isaackogan - I could use your help right quick!

My guess is the issue is because my TypeScript is set to be supported as far back as ES5. https://github.com/infinitered/nsfwjs/blob/master/tsconfig.json#L10

Would you mind pulling the code down, and trying different targets (https://www.typescriptlang.org/tsconfig#target) to see if one of these will remove the offending code?

IF - that's the issue, I can release a second version on NPM that isn't as backwards compatible, but would work well on browser extensions.

Side note: How do you find a list of chrome apps that are using NSFWJS? I'd love to see that list!

Sorry, I forgot all about this issue! I ended up going with a python tensorflow API instead that makes use of the model nsfwjs uses. I am still interested in migrating this detection to the client-side using nsfwjs because it would surely save a lot of computational resources on my own infrastructure and network usage for my clients who have to send the images over.

I will attempt to do some debugging like you've suggested to see if I can't compile a version that works better with Manifest v3. As of a few weeks ago, Chrome stopped accepting new v2 extensions, so this package cannot be used to create Google Chrome apps.

sunil3590 commented 1 year ago

Hey @isaackogan - I'm having the same issue. Were you able to resolve it and use NSFW in a V3 Chrome Extension? Thanks!

shabby2333 commented 8 months ago

I tried to use nsfwjs as ESNext to my MV3 demo. It works when I removed the '@nsfw-filter/gif-frames' library.