r/webdev•
Hoek

Wanted: Browser plugin which asks me for permission before running each javascript block

I'm trying to solve a nasty bug on a large site where a jQuery plugin isn't working as expected. It is, however, working when I extract the problematic code into JSFiddle. Then, it works flawlessly. I suspect some other script polluting the namespace, so I imagine the best way to find the offending script would be to get the browser to ask me permission before loading a .js file or a <script> block.

Does such a thing exist, or how would you debug this kind of problem?

Thank you!

Posted Jul 12, 2013, 9:43 AM UTC

17
elspic•

NoScript - Firefox

NotScript - Chrome

3
Disgruntled__Goat•

Are there any errors in the console? (Firebug if you're using Firefox or Chrome Dev Tools.) If there is a conflict between scripts it seems like there would be an error.

Next, I would remove (comment out) each script block in turn (you have a dev environment, right?) and see if any part fixes the bug, then you know where the problem lies.

Your best solution may be simply to set up jQuery to avoid conflicts:

jQuery.noConflict();
jQuery(function($) {
    // put jquery code here
});
2
nbrogi•

Chrome Inspector to see if any errors..?

1
HoekOP•

There are none, unfortunately. Syntactically, everything is correct, it's just that bad scope encapsulation in some scripts seems to cause variable or functions to be overwritten by 3rd-party scripts which get delivered by one of the ad networks.

1
Pilate•

Have you tried debugging to see exactly whats changing between your jsfiddle version and the live one?

1
nbrogi•

There are none, unfortunately. Syntactically, everything is correct, it's just that bad scope encapsulation in some scripts seems to cause variable or functions to be overwritten by 3rd-party scripts which get delivered by one of the ad networks.

Can you minimize your code (so that all the vars would change, but you would have the source code and you could easily reverse it back to normal), and then let the third-party things run theirs on top of that?

I think that could be a good way to solve the problem quickly.

1
RobbieHart•

You could use a module loader like RequireJS, that wraps your module in a function to which you specify your dependencies.

That way if it really is a namespace problem, the wrapped module will have a clean namespace, but can still be given everything it needs.

1