Skip to content

console.log in tests doesn't work on IE8 and lower #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vedharish opened this issue Jul 27, 2016 · 2 comments · Fixed by #241
Closed

console.log in tests doesn't work on IE8 and lower #164

vedharish opened this issue Jul 27, 2016 · 2 comments · Fixed by #241

Comments

@vedharish
Copy link
Contributor

console.log in tests on IE8 and lower gives the following error -

Launching 1 worker(s) for 1 run(s).
[Windows XP, Internet Explorer 8.0] Failed: 1 tests, 0 passed, 1 failed; ran for 16ms
[Windows XP, Internet Explorer 8.0] Error: "Odd Tests: isOdd()" failed, Died on test #1 undefined: Object doesn't support this property or method
[Windows XP, Internet Explorer 8.0] Screenshot: https://s3.amazonaws.com/testautomation/f5d858132a3cb80355b16a6d6b337b7249dcc601/js-screenshot-1469619378.png

Object doesn't support this property or method

Can reproduce this using browserstack-runner version >= 0.4.2

@jzaefferer
Copy link
Contributor

Probably related to this?

if (typeof console !== 'object') {
var console = {};
window.console = console;
}
_console_log = console.log;
console.log = function () {
var args = BrowserStack.util.toArray(arguments).map(BrowserStack.util.inspect);
post('/_log/', { arguments: args }, function () {});
};
console.warn = function () {
var args = BrowserStack.util.toArray(arguments).map(BrowserStack.util.inspect);
post('/_log/', { arguments: args }, function () {});
};
Though it has been in place pretty long.

@tr4n2uil
Copy link
Contributor

Yup, getting console logs to users console is nice feature, hence raised this issue so we fix it :)

Krinkle added a commit to Krinkle/browserstack-runner that referenced this issue Apr 11, 2021
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 browserstack#161.
Fixes browserstack#164.
Fixes browserstack#212.
Krinkle added a commit to qunitjs/browserstack-runner that referenced this issue Apr 11, 2021
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 browserstack#161.
Fixes browserstack#164.
Fixes browserstack#212.
Ref browserstack#241.
francisf pushed a commit that referenced this issue Apr 21, 2021
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants