With the latest GM (2.2) and FF (32.0.3) one of my GM scripts is causing 
“Permission denied to access object” within the page's script.  I've tried 
all manner of @grants (of which I have some, for local value storage), 
cloneInto, exportFunction, createObjectIn, but no combination I've tried 
can get me past the issue.  Here's a cut down page that shows the issue:

With the latest GM (2.2) and FF (32.0.3) one of my GM scripts is causing 
“Permission denied to access object” within the page's script.  I've tried 
all manner of @grants (of which I have some, for local value storage), 
cloneInto, exportFunction, createObjectIn, but no combination I've tried 
can get me past the issue.  Here's a cut down page that shows the issue 
(the error occurs when you click on the OOO after installing the GM 
script;  before installation, the alert() works as expected):

<html>
<head><title>GM Test</title></head>
<body>
<script stype="text/javascript">
var boolVar = false;
</script>
<div onclick="boolVar = !boolVar; alert('now set to ' + boolVar);">OOO</div>
</body>
</html>

And here's a cut-down version of the GM script.  It uses a 3rd-party hook 
to allow the GM script to watch for changes to a page-side variable.  In 
this example, the GM script isn't even doing anything with the change 
notification, but the mere act of adding the hook stop the page accessing 
its own boolVar variable.  I've tried exporting the new property, all the 
functions, etc., but have run out of ideas.  Any thoughts?

// ==UserScript==
// @name        GM Test
// @namespace   fnxweb-gmtest-1
// @version     1
// @grant       GM_getValue
// @grant       GM_setValue
// @grant       GM_listValues
// @grant       GM_deleteValue
// @grant       unsafeWindow
// ==/UserScript==


/*
 * object.watch polyfill
 *
 * 2012-04-03
 *
 * By Eli Grey, http://eligrey.com
 * Public Domain.
 * NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
 */

// object.watch
if (!Object.prototype.watch) {
    Object.defineProperty(Object.prototype, "watch", {
          enumerable: false
        , configurable: true
        , writable: false
        , value: function (prop, handler) {
            var
              oldval = this[prop]
            , newval = oldval
            , getter = function () {
                return newval;
            }
            , setter = function (val) {
                oldval = newval;
                return newval = handler.call(this, prop, oldval, val);
            }
            ;
            if (delete this[prop]) { // can't watch constants
                Object.defineProperty(this, prop, {
                      get: getter
                    , set: setter
                    , enumerable: true
                    , configurable: true
                });
            }
        }
    });
}

/* End object.watch */


function doAlert(id, oldval, newval)
{
    // alert("Changed from " + oldval + " to " + newval);
}

window.wrappedJSObject.watch( "boolVar", doAlert );


-- 
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/greasemonkey-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to