Skip to content

Commit d76b3df

Browse files
Krinklefrancisf
authored andcommitted
Fix bad console assignment
Follows-up 826d2c7. Before that commit, the reason global "console" was globbered is that the `var console` part of the inner `var console = {}` assignment was hosted by the JavaScript engine. Thus the variable always existed in the local scope as type "undefined", and so the conditional check never saw the real console, and always created a custom one. Thus it always deleted the original console reference, as well as any other it contained. In commit 826d2c7, this was incorrectly fixed by assigning the unchecked expression referring to `console`, thus no longer having a fallback to `{}` in older browsers, because an unchecked reference like that throws an Uncaught ReferenceError. As a result, browserstack-runner was unable to run in IE 9 or older. Fixes #161. Fixes #164. Fixes #212.
1 parent d75cbb4 commit d76b3df

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/_patch/browserstack.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@
3737
req.send(data);
3838
}
3939

40-
var browserstack_console = console || window.console || {};
40+
// Change some console method to capture the logs.
41+
// This must not replace the console object itself so that other console methods
42+
// from the browser or added by the tested application remain unaffected.
43+
// https://github.com/browserstack/browserstack-runner/pull/199
44+
var browserstack_console = window.console || {};
4145
browserstack_console.log = function () {
4246
var args = BrowserStack.util.toArray(arguments).map(BrowserStack.util.inspect);
4347
post('/_log/', { arguments: args }, function () {});
@@ -54,6 +58,7 @@
5458
BrowserStack.worker_uuid = getParameterByName('_worker_key');
5559

5660
window.BrowserStack = BrowserStack;
61+
// If the browser didn't have a console object (old IE), then this will create it.
62+
// Otherwise this is a no-op as it will assign the same object it already held.
5763
window.console = browserstack_console;
58-
console = browserstack_console;
5964
})();

0 commit comments

Comments
 (0)