Upcoming issues in Firefox 57 and GreaseMonkey 4.0 (Nov 14!)
Hey everybody!
I only just now noticed that GreaseMonkey 4.0 that will be enabled on Firefox 57 (to be released November 14th already!) will have various backwards-incompatible changes. With the new extensions framework in Firefox, the authors of GreaseMonkey claim to be unable to provide some of the old functionality + they want to take this opportunity to fix some of the API. Below you can find a list of changes and at the bottom you can find several solutions.
I'm not a script author, what does this mean for me?
As of November 14, you'll most likely receive the Firefox 57 update. As of that point GreaseMonkey will not be able to run most of your userscripts. Therefore it is advisable to install TamperMonkey on Firefox instead and carry over all your userscripts one by one.
What will be changed?
Several changes to the API: while some objects will remain available for a while as they are, they are considered deprecated and might not work in a new version.
All the GM_* functions have been moved to a GM object (see the API). GM_info, for example, will be available under GM.info. Some functions also changed slightly, such as GM_xmlhttpRequest which became GM.xmlHttpRequest and GM_getResourceURL became GM.getResourceUrl.
Also, several methods will now return promises instead of direct results. This makes doing some things quite a bit more complicated...
Global variables won't be available from the script any more. Pretty much all our scripts will break on this! If you want to access the Waze or OpenLayers variables, you'll need to use unsafeWindow.Waze instead. This also works in TamperMonkey, in case you were wondering. Also, this means that if you provide an object or function as parameter in a function of the page, you will need to transform it with the cloneInto or exportFunction (see more about this at the bottom of the post).
Solutions
TamperMonkey works fine on Firefox 57, so this seems like our best bet. This is something all users will have to do though and the switch isn't too easy to make as you'll need to install each userscript from the start again. Luckily most userscripts use localStorage for storing their data, so those userscripts will work exactly the same in TamperMonkey.
If you want to get your script to work on GreaseMonkey 4.0 as well, you'll need to make various changes that are not always as easy to make. These require a good knowledge of JavaScript and an understanding on how the different executions contexts work within Firefox.
I've listed the most important code changes here:
Access global variables through unsafeWindow
If you use the OL, Waze, I18n or another global variable from the WME, you'll need to retrieve them from the unsafeWindow object like so:As this would require changing your script a lot, I'd advice you to add a line like below at the top of your script:
Clone/export your objects and functions you use in global functions
If you were to, for example, add a function to be called on a certain event with a call to the setEventListener of an element, you'll need to export that function to the unsafeWindow environment. Otherwise the object will attempt to call a function that is in the context of the userscript, which will throw a security violation error. This also applies for objects, though GreaseMonkey usually manages to clone easy objects automatically.
This can be done as such:
Call the new API methods instead of the old ones
The problem with this is that TamperMonkey and others don't necessarily support this new API. A solution proposed by GreaseMonkey is to use this polyfill (a piece of JavaScript code that emulates the new API with the old functions) and switch over to the new API. I'd generally advice against using these functions too much anyway as you tend not to really need them. At this point I'd prefer to await what the TamperMonkey team is going to do.
It can be done as I have a very complex userscript that worked just fine in the new version, but it is a lot of work, which probably isn't worth it now that TamperMonkey also works on Firefox.
I only just now noticed that GreaseMonkey 4.0 that will be enabled on Firefox 57 (to be released November 14th already!) will have various backwards-incompatible changes. With the new extensions framework in Firefox, the authors of GreaseMonkey claim to be unable to provide some of the old functionality + they want to take this opportunity to fix some of the API. Below you can find a list of changes and at the bottom you can find several solutions.
I'm not a script author, what does this mean for me?
As of November 14, you'll most likely receive the Firefox 57 update. As of that point GreaseMonkey will not be able to run most of your userscripts. Therefore it is advisable to install TamperMonkey on Firefox instead and carry over all your userscripts one by one.
What will be changed?
Several changes to the API: while some objects will remain available for a while as they are, they are considered deprecated and might not work in a new version.
All the GM_* functions have been moved to a GM object (see the API). GM_info, for example, will be available under GM.info. Some functions also changed slightly, such as GM_xmlhttpRequest which became GM.xmlHttpRequest and GM_getResourceURL became GM.getResourceUrl.
Also, several methods will now return promises instead of direct results. This makes doing some things quite a bit more complicated...
Global variables won't be available from the script any more. Pretty much all our scripts will break on this! If you want to access the Waze or OpenLayers variables, you'll need to use unsafeWindow.Waze instead. This also works in TamperMonkey, in case you were wondering. Also, this means that if you provide an object or function as parameter in a function of the page, you will need to transform it with the cloneInto or exportFunction (see more about this at the bottom of the post).
Solutions
TamperMonkey works fine on Firefox 57, so this seems like our best bet. This is something all users will have to do though and the switch isn't too easy to make as you'll need to install each userscript from the start again. Luckily most userscripts use localStorage for storing their data, so those userscripts will work exactly the same in TamperMonkey.
If you want to get your script to work on GreaseMonkey 4.0 as well, you'll need to make various changes that are not always as easy to make. These require a good knowledge of JavaScript and an understanding on how the different executions contexts work within Firefox.
I've listed the most important code changes here:
Access global variables through unsafeWindow
If you use the OL, Waze, I18n or another global variable from the WME, you'll need to retrieve them from the unsafeWindow object like so:
Code: Select all
unsafeWindow.Waze
Code: Select all
var OL = unsafeWindow.OL;
If you were to, for example, add a function to be called on a certain event with a call to the setEventListener of an element, you'll need to export that function to the unsafeWindow environment. Otherwise the object will attempt to call a function that is in the context of the userscript, which will throw a security violation error. This also applies for objects, though GreaseMonkey usually manages to clone easy objects automatically.
This can be done as such:
Code: Select all
// using a function as parameter
document.getElementById('someButton')
.addEventListener('click', exportFunction(someFunction, unsafeWindow));
// using an object as parameter
unsafeWindow.$(element).tooltip(cloneInto({
trigger: 'hover'
}, unsafeWindow));
The problem with this is that TamperMonkey and others don't necessarily support this new API. A solution proposed by GreaseMonkey is to use this polyfill (a piece of JavaScript code that emulates the new API with the old functions) and switch over to the new API. I'd generally advice against using these functions too much anyway as you tend not to really need them. At this point I'd prefer to await what the TamperMonkey team is going to do.
It can be done as I have a very complex userscript that worked just fine in the new version, but it is a lot of work, which probably isn't worth it now that TamperMonkey also works on Firefox.
Re: Upcoming issues in Firefox 57 and GreaseMonkey 4.0 (Nov