FF API Changes


I'm struggeling with the recent API changes to unsafeWindow in Firefox 30++.

Could somebody point me in the right direction on how to use cloneInto(), exportFunction(), and createObjectIn() in a Greasemonkey Script?

For example - this is what I did before:

var uw = unsafeWindow || window, $ = uw.jQuery; //JQuery is alreay included into the page

$(document).ajaxComplete(function (event, xhr, settings) {
  alert("Ajax Call");

I know that I can inject this as a script directly into page but I don't wanna miss out on the GM_ functions. What do I need to do to make this work?

Re: @Quackmaster:

I don't wanna miss out on the GM_ functions.

If you are using @grant none then you probably won't have access to the GM_* functions. If you are in the Sandbox, by using any other @grant access right, you should have access to the GM API. Since I haven't had much time to examine this change, or test this, I can't with all certifiable accuracy confirm this... but this is how it looks to me especially with greasemonkey/greasemonkey@7031a32.

Sry I'm trying to be more clear :)
Currently I'm using:

  • GM_listValues
  • GM_getValue
  • GM_setValue
  • GM_deleteValue
  • GM_info
  • GM_xmlhttpRequest
  • unsafeWindow

I used @grant to allow the usage

In my script I access many objects in the page-script which worked fine via unsafeWindow. I also use $(document).ajaxComplete to check wether the game (Grepolis) has opened certain windows or started some functions. I can still do that if I inject my script via

function main () {
//my script
var script = document.createElement('script');
script.appendChild(document.createTextNode('('+ main +')();'));

The problem with this would be that I can't access the GM_* Functions from there which I use to save the script's settings, do a little GM_xmlhttpRequest to my site to count how many people are using the script and to provide a little update notice (I compare the @versions of the script and the meta.js every 24 hours).

Re: @Quackmaster:

cloneInto would work here.

var privilegedFunctions = {
    myCallback: function (event, xhr, settings) {
        console.log('myCallback works as expected!');

function myScope() {
    console.log('myScope works as expected!');

privilegedFunctions = cloneInto(privilegedFunctions, unsafeWindow, {cloneFunctions: true});


Just wanted to say thank you! cloneInto was the way to go and your example code provided enough help to make the necessary changes to my script. :)