question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] GM_setValue does not work properly with a modest volume of data.

See original GitHub issue

Description The function GM_setValue does not working when storing large amounts of data across different variables. If the script stores data using GM_setValue, the function seems to work as expected. However, after reloading the page and trying to retrieve the data previously written, it returns undefined, just as if the item has not been stored previously.

Steps to reproduce

I’ve attached here a small userscripts that shows the bug. The example webpage is also included: WEBPAGE:

<!DOCTYPE html>
<html lang="en">
<body>
<div id="main">

<button id="b1">Read</button>
<button id="b2">Create</button>

</div>
</body>
</html>

USERSCRIPT:

// ==UserScript==
// @name        New script - localhost:44444
// @namespace   Violentmonkey Scripts
// @match       http://localhost:44444/empty.html
// @grant       none
// @version     1.0
// @author      -
// @grant       GM.deleteValue
// @grant       GM.getValue
// @grant       GM.setValue
// @grant       GM.registerMenuCommand
// @description 19/9/2022, 20:08:06
// ==/UserScript==




function readdata()
{
  ;(async () => {
    console.log("Results");
    console.log(await GM.getValue('d1'));
    console.log(await GM.getValue('d2'));
    console.log(await GM.getValue('d3'));
    console.log(await GM.getValue('d4'));
    console.log(await GM.getValue('d5'));
    console.log(await GM.getValue('d6'));
    console.log(await GM.getValue('d7'));
    console.log(await GM.getValue('d8'));
    console.log(await GM.getValue('d9'));

  })();
}

function createdata()
{
  ;(async () => {
      var arr_temp=[];
      for (i=0;i<1000000;i++)
        {
          arr_temp.push(i);
        }
      
    
    await GM.deleteValue('d1');
    await GM.deleteValue('d2');
    await GM.deleteValue('d3');
    await GM.deleteValue('d4');
    await GM.deleteValue('d5');
    await GM.deleteValue('d6');
    await GM.deleteValue('d7');
    await GM.deleteValue('d8');
    await GM.deleteValue('d9');
    
    await GM.setValue('d1',arr_temp);
    await GM.setValue('d2',arr_temp);
    await GM.setValue('d3',arr_temp);
    await GM.setValue('d4',arr_temp);
    await GM.setValue('d5',arr_temp);
    await GM.setValue('d6',arr_temp);
    await GM.setValue('d7',arr_temp);
    await GM.setValue('d8',arr_temp);
    await GM.setValue('d9',arr_temp);
    
     console.log("DONE");
    location.reload();
})();
  
}
  

document.getElementById("b1").onclick=readdata;
document.getElementById("b2").onclick=createdata;

GM.registerMenuCommand( "read", readdata );
GM.registerMenuCommand( "create", createdata );


Steps:

  1. Click on the “Create” button. It will populate the d1,d2,… variables. It will also reload the page
  2. Click the “read” button. It will print data on the console

Expected behavior

The console prints 9 times an array with 1000000 values.

Actual behavior Sometimes, one or two of the d1,d2,… variables is undefined. Each time the steps are repeated, the undefined variables change. It reminds me of a race condition of sorts.

Environment:

  • OS: Linux Ubuntu 22.04.1
  • Kernel: Linux 5.15.0-47
  • Browser: Firefox 104.0.2
  • Violentmonkey Version: 2.13.1

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tophfcommented, Sep 24, 2022

I’m still working on rewriting our handling of storage, it’ll take some time because we have to support both the old synchronous and the new asynchronous API and I’m trying various solutions to find the one that’s both fast and not overly complicated under the hood. Storing so much data is an edge case which doesn’t affect the majority of scripts, so maybe we should make a new release without waiting for this one, @gera2ld.

0reactions
chocolateboycommented, Oct 8, 2022

Thanks, can confirm this is fixed in v2.13.2 for GM_setValue (i.e. the synchronous version - the release notes make it sound like it only affected the async version 😃 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

setValue doesn't update an object properly, eg dates #5724
During updating of the form I set this object using setValue . However, it is not updating properly. For example, the date property...
Read more >
AFAttribute SetValue does not work correctly in a loop
If I am writing values to AF (lets say they are just <none> data reference types, so internal attributes to AF) via the...
Read more >
updateChildValues() does not work, but setValue() does
I expect it to create the user_orders node, and child node with my userid and put a value there. If I use setValues...
Read more >
Unable to SetValue on system or UDF fields - SAP Community
Hi Aris,. You can only select value from system table as the data source. As you got the exact error message: The item...
Read more >
ValueError: Row: Invalid Input Type For Set Value
I keep getting this error: On Line 65 - ValueError: Row: Invalid input value for SetValue. Code is as follows: import arcpy, time,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found