My favorites | Sign in
Project Home Downloads Wiki Issues Source
New issue   Search
  Advanced search   Search tips   Subscriptions
Issue 1: Don't set javascript methods to "null"
19 people starred this issue and may be notified of changes. Back to list
Status:  New
Owner:  ----

Sign in to add a comment
Reported by, Apr 11, 2011

I'm working for a big social networking site where we log javascript exceptions happening in the user's browser.
In the past weeks one strange js error caught our attention:
"Uncaught TypeError: Property 'scrollTo' of object [object DOMWindow] is not a function"

The strange thing about this error is that it only appeared in Chrome.
After some investigation I found this extension which seems to be the cause for this error.

In line #100 of blockStart.js a bunch of javascript functions (including window.scrollTo) is set to 'null'.
I can fully understand that unsetting those variables makes sense.

The only problem I have is that the type of the variable is changed which leads to javascript exceptions and prevents other "non-annoying" functionality from being executed.

Imagine this piece of code:
window.scrollTo(0, 0); // <-- not a function, therefore causes a js exception
doSomethingElseImportant(); // <-- will never be executed when window.scrollTo is null

If the extension is enabled the "doSomethingElseImportant()" will never be executed since the window.scrollTo method throws a js error which stops javascript execution at that point.

Would be really helpful if the "Better PopUp Blocker" would preserve the original type.
So instead of setting all those javascript functions to null, it would make more sense to set them to an empty function. "window.scrollTo=function(){};"


Dec 23, 2011
So true! This is unbelievably frustrating for me as a user!
Feb 7, 2012
I believe this quick-and-dirty patch should improve the situation.
1.3 KB   View   Download
May 29, 2012
Well, setting getSelection to undefined still breaks some sites and extensios (namely, Evernote's Clearly). The following should work better: "document.getSelection=window.getSelection=function(){return new Object};"

A proper way, I believe, should be to proxy calls, but replace any unsafe methods on resulting DOMSelection object with dummy functions.
May 30, 2012
It's definitely a better approach. The only problem I can see is with naive feature detection:

window.scrollTo = function () { return new Object }
window.scrollTo && doThingsThatUseScrollTo(); //happens

window.scrollTo = null;
window.scrollTo && doThingsTheUseScrollTo(); //never happens

However I can't see this being a problem because all the functions being nulled by blockstart.js are being discarded intentionally.
Mar 6, 2014
We're seeing these exceptions on as well. (I'm a GitHub engineer.)
Sign in to add a comment

Powered by Google Project Hosting