Adding options to a select with the options array doesn't work any more #1510

Closed
Spamme1 opened this Issue Feb 6, 2012 · 7 comments

Projects

None yet

4 participants

Spamme1 commented Feb 6, 2012

I have some scripts adding options to a select as follow:

select.options[select.options.length]=new Option("test")

Since I have updated to firefox 10 it doesn't work any more.

Collaborator
arantius commented Feb 6, 2012

Confirmed working in 9 and failing in 10.

No idea why. The equivalent code in the Web Console works. This syntax:

var o = document.createElement('option');
o.value='test 2';
o.textContent='test 2';
s.appendChild(o);

Works, so I'd suggest switching to that as a workaround for now.

I'm experiencing a similar issue one of my greasemonkey scripts. The following works in Firefox 9, but stopped working in Firefox 10:

document.getElementById('aSelect').options.length = 0;
// Options in "aSelect" are not removed in Firefox 10

Strangely enough I found this workaround:

document.getElementById('aSelect').options.length;
document.getElementById('aSelect').options.length = 0;
// Options in "aSelect" are removed

For some reason merely accessing options.length more than once makes it work as expected.

Looks like Mozilla is aware of this issue: https://bugzilla.mozilla.org/show_bug.cgi?id=715156

Contributor

Is it really a mistake of Firefox?

OK:
https://gist.github.com/4167820

ERROR (only one new line: @grant GM_getValue):
https://gist.github.com/4167825

Collaborator

Given the known state of the bug, yes. Adding a grant where none is necessary (like the test case you provided) throws Greasemonkey into the legacy heavy-wrapper mode, which triggers the upstream bug, as it is these wrappers that are broken. Without it the wrapper isn't there so the bug isn't encountered.

Collaborator

Upstream just added a patch and marked the bug resolved, so nightlies should soon show fixed behavior.

Contributor

Firefox 21.0b1 - error fixed.

@arantius arantius closed this Apr 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment