Skip to content
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

Debug: fix window is undefined bug on next.js framework #168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions src/os.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
export const MACOS = 'macOs';
export const WINDOWS = 'windows';
"use strict";

export default function os() {
// explicitly set these to avoid issues
const w = window || null;
const n = navigator || null;
const p = process || (w && w.process) || null;
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.default = os;
var MACOS = (exports.MACOS = "macOs");
var WINDOWS = (exports.WINDOWS = "windows");

function os() {
// Check if we are running in a browser
var isBrowser =
typeof window !== "undefined" && typeof navigator !== "undefined";

// get process from window if it exists there
var p = isBrowser ? window.process : process;

// via node
if (p && p.platform) {
if (p.platform === 'darwin') {
if (p.platform === "darwin") {
return MACOS;
}
if (p.platform.includes('win')) {
if (p.platform.includes("win")) {
return WINDOWS;
}
}

// via user agent
if (n && n.userAgent) {
if (n.userAgent.includes('Macintosh')) {
if (isBrowser && navigator.userAgent) {
if (navigator.userAgent.includes("Macintosh")) {
return MACOS;
}
if (n.userAgent.includes('Windows')) {
if (navigator.userAgent.includes("Windows")) {
return WINDOWS;
}
}
Expand Down