Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GM_xxx in jQuery events #1626

Aymkdn opened this issue Sep 10, 2012 · 2 comments

GM_xxx in jQuery events #1626

Aymkdn opened this issue Sep 10, 2012 · 2 comments


Copy link

@Aymkdn Aymkdn commented Sep 10, 2012

Hi guys,

I load jQuery on a page with Greasemonkey, then I use some GM_setValue and GM_getValue, and finally I use the jQuery events.
My code is as simple as this one :

// ==UserScript==
// @name        Test
// @description test
// @include
// @version     1
// @grant       GM_setValue
// @grant       GM_getValue
// @unwrap
// ==/UserScript==

var GM_JQ = document.createElement('script');
GM_JQ.src = '';
GM_JQ.type = 'text/javascript';

// things to do when jQuery is loaded
function letsJQuery() {
  GM_setValue("test","debug"); // save this value
  $('#gbqfq').click(function() {
    // the below code doesn't work, GM_getValue is a function but returns undefined
    // the below code works and returns the correct value
    //setTimeout(function() { alert(GM_getValue("test")); },150);

// Check if jQuery's loaded
function GM_wait() {
  if(typeof unsafeWindow.jQuery == 'undefined') { unsafeWindow.setTimeout(GM_wait,100); }
  else { $ = unsafeWindow.jQuery; jQuery = unsafeWindow.jQuery; letsJQuery(); }

It appears that if we call GM_getValue into a jQuery Event call then GM_getValue returns undefined. We need to call GM_getValue with a setTimeout.
I guess it's a context problem ?


This comment has been minimized.

Copy link

@arantius arantius commented Sep 10, 2012

This is known/expected due to limitations of the security sandbox. See:

@arantius arantius closed this Sep 10, 2012

This comment has been minimized.

Copy link

@Aymkdn Aymkdn commented Sep 10, 2012

Oh OK I missed that. Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.