Skip to content

Commit

Permalink
[browser] Improve compatibility of getCurrentContext (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrHeinz committed Aug 8, 2024
1 parent 393d505 commit 5601075
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions packages/browser/src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,22 @@ export class Browser extends Base {
}

protected getCurrentContext(): Context {
return {
context: {
url: window.location.href,
user_locale: (navigator as any).userLanguage || navigator.language,
user_agent: navigator.userAgent,
device_pixel_ratio: window.devicePixelRatio,
screen_width: window.screen.width,
screen_height: window.screen.height,
window_width: window.innerWidth,
window_height: window.innerHeight,
},
};
const context: Context = {};

if (typeof window !== "undefined") {
context.url = window.location?.href;
context.device_pixel_ratio = window.devicePixelRatio;
context.screen_width = window.screen?.width;
context.screen_height = window.screen?.height;
context.window_width = window.innerWidth;
context.window_height = window.innerHeight;
}
if (typeof navigator !== "undefined") {
context.user_locale = (navigator as any).userLanguage || navigator.language;
context.user_agent = navigator.userAgent;
}

return context;
}

private configureFlushOnPageLeave(): void {
Expand Down

0 comments on commit 5601075

Please sign in to comment.