Adding an @require breaks Greasemonkey (when files are locked) #1466

john-sanders-2 opened this Issue Nov 10, 2011 · 6 comments


None yet

3 participants


I'm using Firefox 8.0, Greasemonkey 0.9.12, on Windows 7 (all latest updates).

I've been using a hand rolled Greasemonkey script to update parts of an Intranet page I use all the time. I changed the require tag to use the latest jQuery and the script stopped executing.

After a lot of testing, I've broken the problem down to the smallest parts possible to see if I was doing something wrong. I have:

  1. Created a new profile.
  2. Installed Greasemonkey, and created a new script for the page.
  3. The only code added was: alert('working');
  4. Verified the script worked, and it does.
  5. Edited the script again (GM icon->manage scripts->edit), and added a require tag to bring in jQuery 1.7 (although any version I've tried causes the same problem). The script fails to run.

My entire script reads as follows (domain name changed):

// ==UserScript==
// @name           Helper Scripts
// @namespace      w
// @include*
// @require
// ==/UserScript==


The script stops working. Does not kick any errors or warnings in the Javascript console. I did notice the config.xml does get updated, but not correctly (i presume). Here's the result of the config.xml after I load the test page:

    <Script filename="helper_scripts.user.js" name="Helper Scripts" namespace="w" description="" version="" enabled="true" runAt="document-end" basedir="helper_scripts" modified="1320954850701" dependhash="30ee872c576e6e700ef9c9ad7e01f8605a750f52" updateAvailable="" lastUpdateCheck="">
        <Require filename=""/>

I'm assuming that the GM adding the tag with the empty filename attribute is messing things up. If you edit the XML directly, and reload, GM will wipe it out and revert it back to an empty attribute again.

I'm perplexed, and would love to have my GM scripts back. Any help would be appreciated.

John Sanders


A work around that seems to fix the problems in config.xml, and allows scripts to run...

  1. Get the file path to the broken script.
  2. In the Firefox URL, type file:///< file path to broken script >
  3. GM will see this as a user script to install, it will overwrite your current version that is broken, and set up config.xml properly.
  4. Reload the page with the broken script. Should work.

Example of my file path URL:



I can't reproduce.

zewt commented Dec 18, 2011

This is happening to me, too, triggering:

Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIFile.remove]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: chrome://greasemonkey/content/script.js :: <TOP_LEVEL> :: line 507" data: no]

This is the remove() call in:

// Get rid of old dependencies.
var dirFiles = this._basedirFile.directoryEntries;
while (dirFiles.hasMoreElements()) {
  var nextFile = dirFiles.getNext()
  if (!nextFile.equals(this.file)) nextFile.remove(true);

That tries to remove Vim's .swp file, which fails since the file is open and locked. This should be more selective about what it deletes, and not fail entirely if removing a single file fails.

A more usable workaround is to close Vim (or whatever you're using that's creating a lockfile) after changing dependencies, and reload the page to cause dependencies to be updated while your editor is closed.


Interesting! Thanks for that report, zewt. What platform are you running vim on that locks files? On both Linux and Windows (cygwin) I can delete the .swp file.

The right fix is probably to find require/resource/icon entries for the old version of the script, and just deleting those files. Detecting and warning for failure (rather than breaking like this) if even that fails, while we're at it, is probably good too.

zewt commented Dec 19, 2011

A native Windows build (not cygwin). See the top link (currently gvim73_46.exe) at

Windows locks all opened files by default, including files opened with fopen(); the only way to open files without locking is to use a lower-level Win32 API to explicitly disable it. Cygwin may be doing just that in order to more closely emulate Unix, where files aren't locked by default, which may be why you're not seeing this with a Cygwin build of Vim.

@arantius arantius added a commit that closed this issue Jan 25, 2012
@arantius arantius Only delete files explicitly known to be depdencies, in update.
Rather than just everything in the directory besides the script itself, in case there are extra files (e.g. locked vim ".swp" files).

Fixes #1466
@arantius arantius closed this in 8ceb225 Jan 25, 2012

Reporters: Please test and report whether this build fixes your issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment