Drupal.Settings variables not found in Firefox 3 when javascript aggregation is turned on

rob_connolly - July 23, 2008 - 08:48
Project:Drupal
Version:6.4
Component:javascript
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

Hi,

I'm getting an intermittent Javascript error when the lightbox2 module is enabled. I only noticed this because I happened to have firebug turned on for my site!

s is undefined
[Break on this error] Lightbox.overlayOpacity = s.overlay_opacity;

This seems to be causing all subsequent scripts on the page from running and it only happens sometimes, seemingly randomly to me!

If it's any help, I have Javascript compression turned on, though I don't think that should make any difference.

Cheers,

Rob

#1

stella - July 23, 2008 - 22:16

I can't reproduce it. I've enabled js compression on my site, so we'll see if it starts happening over the next week or so. Does it happen in all browsers?

Can you try out the latest dev release of the module? I did make some changes earlier in the week because the YUI compressor app gave errors whenever it tried to compress the lightbox.js file. I'm not totally sure this will help though, because the s variable in question is just an alias of Drupal.settings.Lightbox2 which Drupal generates on behalf of the lightbox2 module. If s is undefined, then that means Drupal.settings.Lightbox2 is undefined too, which can't be right.

Anyway try the latest dev version of the module to see if it helps. Can you send me a link to your site also? My contact form is enabled if you wish to do so privately.

Cheers,
Stella

#2

stella - August 8, 2008 - 14:23
Status:active» active (needs more info)

I still haven't encountered this issue. Is it still a problem for you? Have you tried using the latest dev version of the module?

Cheers,
Stella

#3

Reg - August 15, 2008 - 01:47

I'm running a site in 5.x but I think I can add some information here as I just started getting this error.

I took out the compression in the JavaScript but left in the code that joins all the JS files together and got the same error. However, when the files are loaded separately, no error.

I also never had this problem in FF2 so I am considering the possibility that it is an FF3 bug (no problem in IE7 either), it is a pretty new browser and may still have a the odd quirk we don't know about.

Looking at the loaded object, sure enough "Drupal.settings" does not exist. It is created with a small bit of inline JS which for some reason isn't doing that occasionally. If I was to make a guess on this issue I would say that when it's loading 15-20 JS files they don't have time to run any code so the inline JS code that creates the "Drupal.settings" always does it's job first but when just one JS file loads perhaps that is not always the case. I can't prove this, for one thing my JS troubleshooting isn't that great, but I'm hoping these ideas and what I have done so far helps someone else maybe take it another step.

Any page on my website such as: http://www.lightingatwillowglen.com/craftsman-pendant-small-17902 will produce this error in FF3... if it chooses to at the time...

I suspect this could be moved to be a core issue being that the creation of "Drupal.settings" is controlled by the core.

If anyone else has anything to add please do. Intermittent problems are tough to crack.

-Reg

#4

stella - August 15, 2008 - 09:21
Project:Lightbox2» Drupal
Version:6.x-1.8» 6.4
Component:Javascript» javascript
Status:active (needs more info)» active

Reg: I can reproduce the issue on your site.

It doesn't happen for the Lightbox2 javascript code, but on a js file from another module. I'm not quite sure which (since js compression is enabled), but it happens on line 13 of your compressed js file. So I'm confident that this isn't a problem with the lightbox2 module.

However, I think I've narrowed it down. I find that it only happens when firebug is enabled for a site. It has to be totally disabled in order for the error to not appear. By "totally disabled", I don't just mean that the firebug window isn't open, I mean that either the firebug add-on isn't installed or that all the panel options are disabled under the "Console" tab. If it's disabled, I never see the error, no matter how many page refreshes I do (clearing the cache each time). However if it's enabled, then the "Drupal.settings is undefined" error appears fairly regularly, but not on every page load.

I'm re-assigning this to the Drupal project, as it's definitely not a Lightbox2 issue. However I'm not sure if this is a Drupal or a Firebug issue. I'm leaning towards the latter however.

Cheers,
Stella

#5

Reg - August 15, 2008 - 21:10

Yep, I came to the same conclusion before I wrote you and I agree that it is most likely a FF3 issue and more specifically a FF3 plugin issue. As for which module it happens for, I think that is simple, the first module that tries to access the "Drupal.settings" object triggers it which will probably be different for each website. I'll leave my website "as is" as best I can for the short term so the JavaScript team can have a look it at.

#6

Lukas2000 - August 17, 2008 - 18:39

We have this issue on our site as well. It is most definitely a firefox 3 related issue and likely has something to do with Caching. It also only occurs when Javascript aggregation is turned on. The first page load works just fine, but when a user navigates to a second page, any variable that contains "Drupal.settings...." no longer functions.

We are using Drupal 5.7.

#7

aerodog - August 17, 2008 - 18:41
Version:6.4» 5.9
Priority:normal» critical

I'm feelin your pain Lukas2000. Same exact issue here. If you google around you'll see some threads pertaining to this issue with post dates that coincide with the release of firefox 3. I don't know what exactly this is...any more info would be greatly appreciated...

#8

Lukas2000 - August 17, 2008 - 18:43
Title:Intermittent Javascript error» Drupal.Settings variables not found in Firefox 3 when javascript aggregation is turned on
Priority:critical» normal

Changing the title so that it's more appropriate

#9

Sam Dark - August 20, 2008 - 11:52

Same problem…

#10

Reg - August 21, 2008 - 23:32

I suspect the only solution is to wait until an update of an FF3 plug-in is available but it would be nice if someone from the JavaScript team would at least have a look at it.

#11

davebv - August 29, 2008 - 21:52
Version:5.9» 6.4

I am writing a module which passes a variable through Drupal.settings.

My variable is called prueba so when I try to use it on the js file: Drupal.settings.prueba is undefined.

I happens when debuggin, when it tries to execute the script, the Drupa.settings hast not been extended yet so my variable is not defined, but then, I continue and, after that, my variable is present according to the dom.

What I do is:

<?php
mymodule_init
() {

$var_prueba = array(
 
'prueba' => 'prueba' );

drupal_add_js(array('mymodule' => $var_prueba),'setting');

drupal_add_js($path.'/js/myjs.js','module','header');
}
?>

in myjs.js

alert(Drupal.settings.mymodule.prueba) ;

and the error: Drupal.settings.mymodule.prueba is undefined

 
 

Drupal is a registered trademark of Dries Buytaert.