gm4-polyfill

This utility is designed to ease authoring user scripts compatible with both Greasemonkey 4 and other/older user script engines.

Include it in your script like:

// @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js

Read the source of the file for more details.