My favorites | Sign in
Project Home Downloads Wiki Issues Source
New issue   Search
for
  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 christop...@googlemail.com, Apr 11, 2011
Hi,

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:
doSomething();
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(){};"

Thanks!

Christopher
Dec 23, 2011
#1 idle...@gmail.com
So true! This is unbelievably frustrating for me as a user!
Feb 7, 2012
#2 drdae...@gmail.com
I believe this quick-and-dirty patch should improve the situation.
blockStart.js.patch
1.3 KB   View   Download
May 29, 2012
#3 drdae...@gmail.com
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
#4 muld...@gmail.com
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
#5 adam.ro...@gmail.com
We're seeing these exceptions on github.com as well. (I'm a GitHub engineer.)
Sign in to add a comment

Powered by Google Project Hosting