Skip to content

Commit

Permalink
feat(plugin-browser-device) add orientation fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
imjoehaines committed Jun 17, 2020
1 parent 9c778bf commit 64fd89e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions packages/plugin-browser-device/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ const assign = require('@bugsnag/core/lib/es-utils/assign')
/*
* Automatically detects browser device details
*/
module.exports = (nav = navigator, _screen = window.screen) => ({
module.exports = (nav = navigator, screen = window.screen) => ({
load: (client) => {
const device = {
locale: nav.browserLanguage || nav.systemLanguage || nav.userLanguage || nav.language,
userAgent: nav.userAgent
}

if (_screen && _screen.orientation && _screen.orientation.type) {
device.orientation = _screen.orientation.type
if (screen && screen.orientation && screen.orientation.type) {
device.orientation = screen.orientation.type
} else {
device.orientation =
document.documentElement.clientWidth > document.documentElement.clientHeight
? 'landscape'
: 'portrait'
}

client.addOnSession(session => {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-browser-device/test/device.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('plugin: device', () => {
expect(payloads[0].events[0].device.time instanceof Date).toBe(true)
expect(payloads[0].events[0].device.locale).toBe(navigator.language)
expect(payloads[0].events[0].device.userAgent).toBe(navigator.userAgent)
expect(payloads[0].events[0].device.orientation).toBe(undefined)
expect(payloads[0].events[0].device.orientation).toBe('portrait')
})

it('should capture the screen orientation if possible and add it to the event', () => {
Expand Down Expand Up @@ -58,7 +58,7 @@ describe('plugin: device', () => {
expect(payloads[0].device).toBeDefined()
expect(payloads[0].device && payloads[0].device.locale).toBe(navigator.language)
expect(payloads[0].device && payloads[0].device.userAgent).toBe(navigator.userAgent)
expect(payloads[0].device && payloads[0].device.orientation).toBe(undefined)
expect(payloads[0].device && payloads[0].device.orientation).toBe('portrait')
})

it('should capture the screen orientation if possible and add it to the session', () => {
Expand Down

0 comments on commit 64fd89e

Please sign in to comment.