My previous post discussed how to get userscripts working in Google chrome. Although the process is fairly seamless, there is one issue that I have come across. Within Firefox, Greasemonkey scripts run in a well-defined sandbox which provides a level of security. Check out the security section of the Greasespot wiki for more information.
At this point, the sandbox within which Google Chrome runs userscripts is not quite as well defined as the Greasemonkey environment. For that reason, I don’t recommend that ordinary users run userscripts with Chrome until is better supported.
One result of this sandbox issue is that certain aspects of userscripts may not work within Chrome. For example, in my Gmail and Google Apps Sidebar Remover script, the Gmail Greasemonkey API is accessed through the unsafeWindow object. However, within Chrome, the unsafeWindow object doesn’t exist. For that reason, if you are using my script, you will need to do a search for ”unsafeWindow.” and delete all instances.
Here is an example. The first function is the original code, which works within Firefox with Greasemonkey:
loadCallback: function() {
if(!gmailVar && unsafeWindow.gmonkey.isLoaded('1.0')) {
gmailVar = unsafeWindow.gmonkey.get('1.0');
gmailVar.registerViewChangeCallback(methods.onViewChange);
log("viewchange callback registered");
clearInterval(safeLoadTimerId);
log("interval cleared");
}
},
The Second function has been modified to work within Chrome. The only differences are the objects which were originally accessed through unsafeWindow:
loadCallback: function() {
if(!gmailVar && gmonkey.isLoaded('1.0')) {
gmailVar = gmonkey.get('1.0');
gmailVar.registerViewChangeCallback(methods.onViewChange);
log("viewchange callback registered");
clearInterval(safeLoadTimerId);
log("interval cleared");
}
},
Other examples of things which probably won’t work are calls to any aspect of the Greasemonkey API. I don’t use the API, so I’m not entirely sure if any aspects of it have been ported, or not.


