Skip to content

Instantly share code, notes, and snippets.

Created July 9, 2022 14:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Patch the Protestware behavior in sweetalert2

sweetalert2 (npm, github) versions >= 11.4.9 is affected by a protestware behavior (war propaganda).

So here is a quick and easy way to disable this behavior if you use sweetalert2 >= 11.4.20 and gulp.

Install gulp-replace module:

$ npm install --save-dev gulp-replace

Modify your sweetalert2 deployment task in gulpfile.js:

+const replace = require('gulp-replace');
function sweetalert2() {
    return src('node_modules/sweetalert2/dist/sweetalert2.all.min.js')
+        .pipe(replace('Math.random()<.1', 'Math.random()<0'))

As you can see below, the behavior has 10% chance of occuring

But by modifying it to Math.random()<0 it will always be false and will never occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment