diff --git a/javascript/private/fragment.bzl b/javascript/private/fragment.bzl index 05cc0f24dc1f2..d5d6ed1b1d7cb 100644 --- a/javascript/private/fragment.bzl +++ b/javascript/private/fragment.bzl @@ -51,11 +51,18 @@ def closure_fragment( # Wrap the output in two functions. The outer function ensures the # compiled fragment never pollutes the global scope by using its - # own scope on each invocation. + # own scope on each invocation. We must import window.navigator into + # this unique scope since Closure's goog.userAgent package assumes + # navigator and document are defined on goog.global. Normally, this + # would be window, but we are explicitly defining the fragment so that + # goog.global is _not_ window. + # See http://code.google.com/p/selenium/issues/detail?id=1333 wrapper = ( "function(){" + - "return (function(){%output%; return this._.apply(null,arguments);}).apply(" + - "window, arguments);}" + "return (function(){%output%; return this._.apply(null,arguments);}).apply({" + + "navigator:typeof window!='undefined'?window.navigator:null," + + "document:typeof window!='undefined'?window.document:null" + + "}, arguments);}" ) browser_defs = {