Discussions » تطوير

Issue with GM_getValue from GM_listValues array in firefox.

§
Posted: 19-01-2015
Edited: 20-01-2015

Issue with GM_getValue from GM_listValues array in firefox.

This code works in chrome, and nicely gives me a list of variables I have defined.

// ==UserScript==
// @name        ITSM Use default mail client
// @description Makes ITSM use the default email client. (Normally outlook) amongst a lot of other things.
// @namespace   neemspeesweetikveel
// @version     1.66
// @grant       unsafeWindow
// @grant       GM_deleteValue
// @grant       GM_getValue
// @grant       GM_setValue
// @grant       GM_listValues
// @grant       GM_addStyle
// ==/UserScript==

var arry = [];
arry = GM_listValues();
var p =  arry.length ; 
console.log('##=## GM_listValues ' + p );
for ( var p=arry.length-1; p > -1; p-- ) { 
	console.log('##=## ' + p +  '  ' + arry[p]  );  //+ ' = ' +  GM_getValue(arry[p]) );
}

Chrome console log.

2015-01-19 15:13:59.623 ##=## GM_listValues 19
2015-01-19 15:13:59.624 ##=## 18  prbimptICM17311728
2015-01-19 15:13:59.625 ##=## 17  prbdescSVR18147564
2015-01-19 15:13:59.625 ##=## 16  prbdescSVR18110960
2015-01-19 15:13:59.625 ##=## 15  prbdescSVR17967115
/////
2015-01-19 15:13:59.628 ##=## 5  hidelistSVR16457532
2015-01-19 15:13:59.628 ##=## 4  cclistSVR18110960
2015-01-19 15:13:59.628 ##=## 3  cclistSVR17693513
2015-01-19 15:13:59.628 ##=## 2  cclistICM17449674
2015-01-19 15:13:59.629 ##=## 1  ITSMsettingsOptions
2015-01-19 15:13:59.629 ##=## 0  ITSMsettingsActions

Firefox console log.

"##=## GM_listValues 19"
"##=## 18  undefined"
"##=## 17  undefined"
"##=## 16  undefined"
"##=## 15  undefined"
/////
"##=## 5  undefined" 
"##=## 4  undefined" 
"##=## 3  undefined" 
"##=## 2  undefined" 
"##=## 1  undefined"
"##=## 0  undefined"

So Basically GM_getValue( arry[p] ) returns something else in firefox then in chrome.

Does this ring a bell to anyone?

woxxomMod
§
Posted: 19-01-2015

It's broken in the official GM2.3, arantius has somewhat fixed it in his dev fork, and here's an apparently working backport plus a zipped xpi in the attachment (unzip it and drop on the firefox window manually):

--- a/modules/miscapis.js
+++ b/modules/miscapis.js
@@ -127,9 +127,7 @@ GM_ScriptStorage.prototype.listValues = function() {
   }

   // See #1637.
-  var vals = Array.prototype.slice.call(valueNames);
-  vals.__exposedProps__ = {'length': 'r'};
-  return vals;
+  return JSON.stringify(valueNames || []);
 };


@@ -189,8 +187,6 @@ GM_ScriptStoragePrefs.prototype.deleteValue = function(name) {

 GM_ScriptStoragePrefs.prototype.listValues = function() {
   // See #1637.
-  var vals = Array.prototype.slice.call(this.prefMan.listValues());
-  vals.__exposedProps__ = {'length': 'r'};
-  return vals;
+  return JSON.stringify(this.prefMan.listValues() || []);
 };

 // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ //
--- a/modules/sandbox.js
+++ b/modules/sandbox.js
@@ -106,7 +106,12 @@ function createSandbox(aScript, aContentWin, aUrl) {
   }

   if (GM_util.inArray(aScript.grants, 'GM_listValues')) {
-    sandbox.GM_listValues = GM_util.hitch(scriptStorage, 'listValues');
+    // Return plain (JSON) string from chrome, parse it in the sandbox,
+    // to avoid issues with objects (Array) crossing security boundaries.
+    sandbox._GM_listValues = GM_util.hitch(scriptStorage, 'listValues');
+    Components.utils.evalInSandbox(
+        'function GM_listValues() { return JSON.parse(_GM_listValues()); }',
+        sandbox);
   }
   if (GM_util.inArray(aScript.grants, 'GM_openInTab')) {
     sandbox.GM_openInTab = GM_util.hitch(
§
Posted: 19-01-2015

A bug I see,

That explains why somehow the array length is working normal in firefox, but no values to collect from the array.

Thanks wOxxOm, or rather thanks again.

I hope the GreaseMonkey team fixes this in a GA version soon.

I don't want to ask my colleagues to run any beta stuff, but at least I can make my code do, what it should do.

§
Posted: 19-01-2015

https://github.com/greasemonkey/greasemonkey/issues/2033

var list = cloneInto(GM_listValues(), window); works as a temporary fix until they release a perm fix.

§
Posted: 20-01-2015

Thanks TimidScript,

I'm trying to get to the list of created variables to do some housekeeping and delete variables related to long closed cases.

Depending on how long the next release will take (provided it contains the fix) I may want to use the workaround you provided.

§
Posted: 26-02-2015

The workaround was okay in my Firefox 35.01:

var list = cloneInto(GM_listValues(), window);

Now in FF 36 i get a new JS error message:

Permission denied to pass object to privileged code

Is there another way to still work with Greasemonkey 2.3 AND listValues ?

Post reply

تسجيل الدخول إلى مرحلة ما بعد الرد.