Skip to content

Instantly share code, notes, and snippets.

@noraj
Created July 9, 2022 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noraj/b5495bbd2b022eb112f0a32fb08d4ad6 to your computer and use it in GitHub Desktop.
Save noraj/b5495bbd2b022eb112f0a32fb08d4ad6 to your computer and use it in GitHub Desktop.
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'))
        .pipe(dest('build/js/vendor/sweetalert2/'));
};

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

https://github.com/sweetalert2/sweetalert2/blob/31716c6fe72b9afd13ec935be60d0b425738aa7c/src/SweetAlert.js#L237

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