Skip to content

Commit

Permalink
fix: filter out Edge browser by userAgent (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
legomushroom authored and gr2m committed May 5, 2017
1 parent 8642782 commit 79adee8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ function browserSupportsLogStyles () {
return false
}

// edge browser? https://msdn.microsoft.com/en-us/library/hh869301%28v=vs.85%29.aspx
var isEdge = navigator.userAgent.toLowerCase().indexOf('edge') > -1
// http://stackoverflow.com/a/16459606/376773
var isWebkit = 'WebkitAppearance' in document.documentElement.style
// http://stackoverflow.com/a/398120/376773
var isFirebug = window.console && (window.console.firebug || (window.console.exception && window.console.table)) && true
// firefox >= v31? https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
var isFirefoxWithLogStyleSupport = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31

return isWebkit || isFirebug || isFirefoxWithLogStyleSupport || false
return (isWebkit && !isEdge) || isFirebug || isFirefoxWithLogStyleSupport || false
}
19 changes: 19 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ test('browserSupportsLogStyles in WebKit browser', function (t) {
t.end()
})

test('browserSupportsLogStyles in Edge browser', function (t) {
resetBrowserEnvironment({
document: {
documentElement: {
style: {
WebkitAppearance: 'foo'
}
}
},
navigator: {
userAgent: 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10136'
}
})

t.is(browserSupportsLogStyles(), false, 'is false')

t.end()
})

test('browserSupportsLogStyles in Firefox 30', function (t) {
resetBrowserEnvironment({
navigator: {
Expand Down

0 comments on commit 79adee8

Please sign in to comment.