bugsnag-browser-lite
Advanced tools
Comparing version
@@ -0,0 +0,0 @@ interface UserInfo { |
@@ -1,218 +0,8 @@ | ||
import jsonStringify from "safe-json-stringify"; | ||
import ErrorStackParser from "error-stack-parser"; | ||
export var notifyUrl = "https://notify.bugsnag.com"; | ||
var config = { | ||
notifyUrl: notifyUrl, | ||
}; | ||
var _pad = function (n) { return (n < 10 ? "0" + n : n); }; | ||
// Date#toISOString | ||
export function isoDate() { | ||
// from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString | ||
var d = new Date(); | ||
return (d.getUTCFullYear() + | ||
"-" + | ||
_pad(d.getUTCMonth() + 1) + | ||
"-" + | ||
_pad(d.getUTCDate()) + | ||
"T" + | ||
_pad(d.getUTCHours()) + | ||
":" + | ||
_pad(d.getUTCMinutes()) + | ||
":" + | ||
_pad(d.getUTCSeconds()) + | ||
"." + | ||
(d.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) + | ||
"Z"); | ||
'use strict' | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./bugsnag-browser-lite.cjs.production.min.js') | ||
} else { | ||
module.exports = require('./bugsnag-browser-lite.cjs.development.js') | ||
} | ||
// const REPORT_FILTER_PATHS = [ | ||
// "events.[].app", | ||
// "events.[].metaData", | ||
// "events.[].user", | ||
// "events.[].breadcrumbs", | ||
// "events.[].request", | ||
// "events.[].device", | ||
// ]; | ||
function prepareReportJson(report) { | ||
var payload = jsonStringify(report, null, null); | ||
if (payload.length > 10e5) { | ||
delete report.events[0].metaData; | ||
report.events[0].metaData = { | ||
notifier: "WARNING!\nSerialized payload was " + payload.length / 10e5 + "MB (limit = 1MB)\nmetaData was removed", | ||
}; | ||
payload = jsonStringify(report, null, null); | ||
if (payload.length > 10e5) | ||
throw new Error("payload exceeded 1MB limit"); | ||
} | ||
return payload; | ||
} | ||
function sendReport(report, cb) { | ||
if (cb === void 0) { cb = function () { }; } | ||
if (typeof XMLHttpRequest !== "undefined") { | ||
try { | ||
var url = config.notifyUrl; | ||
var req_1 = new XMLHttpRequest(); | ||
req_1.onreadystatechange = function () { | ||
if (req_1.readyState === XMLHttpRequest.DONE) | ||
cb(); | ||
}; | ||
req_1.open("POST", url); | ||
req_1.setRequestHeader("Content-Type", "application/json"); | ||
req_1.setRequestHeader("Bugsnag-Api-Key", config.apiKey); | ||
req_1.setRequestHeader("Bugsnag-Payload-Version", "5"); | ||
req_1.setRequestHeader("Bugsnag-Sent-At", isoDate()); | ||
req_1.send(prepareReportJson(report)); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
else { | ||
console.error("Bugsnag logger: Could not find XMLHttpRequest"); | ||
} | ||
} | ||
export function hasStack(error) { | ||
return (!!error && | ||
(!!error.stack || !!error.stacktrace || !!error["opera#sourceloc"]) && | ||
typeof (error.stack || error.stacktrace || error["opera#sourceloc"]) === | ||
"string" && | ||
error.stack !== error.name + ": " + error.message); | ||
} | ||
function normaliseFunctionName(name) { | ||
return /^global code$/i.test(name) ? "global code" : name; | ||
} | ||
// takes a stacktrace.js style stackframe (https://github.com/stacktracejs/stackframe) | ||
// and returns a Bugsnag compatible stackframe (https://docs.bugsnag.com/api/error-reporting/#json-payload) | ||
function formatStackframe(frame) { | ||
var f = { | ||
file: frame.fileName, | ||
method: normaliseFunctionName(frame.functionName), | ||
lineNumber: frame.lineNumber, | ||
columnNumber: frame.columnNumber, | ||
}; | ||
// Some instances result in no file: | ||
// - calling notify() from chrome's terminal results in no file/method. | ||
// - non-error exception thrown from global code in FF | ||
// This adds one. | ||
if (f.lineNumber > -1 && !f.file && !f.method) { | ||
f.file = "global code"; | ||
} | ||
return f; | ||
} | ||
export function getStacktrace(error) { | ||
if (hasStack(error)) { | ||
return ErrorStackParser.parse(error).map(formatStackframe); | ||
} | ||
return []; | ||
} | ||
function getOsName() { | ||
var osName = "Unknown OS"; | ||
if (navigator.appVersion.indexOf("Win") != -1) | ||
osName = "Windows"; | ||
if (navigator.appVersion.indexOf("Mac") != -1) | ||
osName = "MacOS"; | ||
if (navigator.appVersion.indexOf("X11") != -1) | ||
osName = "UNIX"; | ||
if (navigator.appVersion.indexOf("Linux") != -1) | ||
osName = "Linux"; | ||
return osName; | ||
} | ||
function detectDeviceInfo() { | ||
var nav = navigator; | ||
var nVer = navigator.appVersion; | ||
var nAgt = navigator.userAgent; | ||
var browserName = navigator.appName; | ||
var browserVersion = "" + parseFloat(navigator.appVersion); | ||
var nameOffset, verOffset, ix; | ||
// In Opera, the true version is after "Opera" or after "Version" | ||
if ((verOffset = nAgt.indexOf("Opera")) != -1) { | ||
browserName = "Opera"; | ||
browserVersion = nAgt.substring(verOffset + 6); | ||
if ((verOffset = nAgt.indexOf("Version")) != -1) | ||
browserVersion = nAgt.substring(verOffset + 8); | ||
} | ||
// In MSIE, the true version is after "MSIE" in userAgent | ||
else if ((verOffset = nAgt.indexOf("MSIE")) != -1) { | ||
browserName = "Microsoft Internet Explorer"; | ||
browserVersion = nAgt.substring(verOffset + 5); | ||
} | ||
// In Chrome, the true version is after "Chrome" | ||
else if ((verOffset = nAgt.indexOf("Chrome")) != -1) { | ||
browserName = "Chrome"; | ||
browserVersion = nAgt.substring(verOffset + 7); | ||
} | ||
// In Safari, the true version is after "Safari" or after "Version" | ||
else if ((verOffset = nAgt.indexOf("Safari")) != -1) { | ||
browserName = "Safari"; | ||
browserVersion = nAgt.substring(verOffset + 7); | ||
if ((verOffset = nAgt.indexOf("Version")) != -1) | ||
browserVersion = nAgt.substring(verOffset + 8); | ||
} | ||
// In Firefox, the true version is after "Firefox" | ||
else if ((verOffset = nAgt.indexOf("Firefox")) != -1) { | ||
browserName = "Firefox"; | ||
browserVersion = nAgt.substring(verOffset + 8); | ||
} | ||
// In most other browsers, "name/version" is at the end of userAgent | ||
else if ((nameOffset = nAgt.lastIndexOf(" ") + 1) < | ||
(verOffset = nAgt.lastIndexOf("/"))) { | ||
browserName = nAgt.substring(nameOffset, verOffset); | ||
browserVersion = nAgt.substring(verOffset + 1); | ||
if (browserName.toLowerCase() == browserName.toUpperCase()) { | ||
browserName = navigator.appName; | ||
} | ||
} | ||
// trim the browserVersion string at semicolon/space if present | ||
if ((ix = browserVersion.indexOf(";")) != -1) | ||
browserVersion = browserVersion.substring(0, ix); | ||
if ((ix = browserVersion.indexOf(" ")) != -1) | ||
browserVersion = browserVersion.substring(0, ix); | ||
return { | ||
language: nav.language, | ||
userAgent: nav.userAgent, | ||
time: isoDate(), | ||
osName: getOsName(), | ||
browserName: browserName, | ||
browserVersion: browserVersion, | ||
}; | ||
} | ||
// Javascript Error object contains a `name` property which gives the type of | ||
// error. E.g. SyntaxError, TypeError, RangeError, EvalError | ||
// User can create their own custom error too and give it a custom name | ||
export function prepareBugsnagReport(config, error, opts) { | ||
return { | ||
apiKey: config.apiKey, | ||
payloadVersion: 5, | ||
notifier: { | ||
name: "saltside web", | ||
version: "1.0.0", | ||
url: "https://saltside.se/", | ||
}, | ||
events: [ | ||
{ | ||
exceptions: [ | ||
{ | ||
errorClass: error.name || "[no errorr name]", | ||
message: error.message || "[no errror message]", | ||
stacktrace: getStacktrace(error), | ||
}, | ||
], | ||
device: detectDeviceInfo(), | ||
app: { | ||
releaseStage: "development", | ||
}, | ||
metaData: opts ? opts.metaData : undefined, | ||
user: opts ? opts.user : undefined, | ||
}, | ||
], | ||
}; | ||
} | ||
function notify(error, opts) { | ||
sendReport(prepareBugsnagReport(config, error, opts)); | ||
} | ||
var bugsnagClient = { | ||
notify: notify, | ||
}; | ||
export function init(apiKey) { | ||
config.apiKey = apiKey; | ||
return bugsnagClient; | ||
} |
{ | ||
"name": "bugsnag-browser-lite", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "", | ||
"main": "./dist/index.js", | ||
"module": "dist/bugsnag-browser-lite.esm.js", | ||
"umd:main": "dist/bugsnag-browser-lite.umd.production.min.js", | ||
"unpkg": "dist/bugsnag-browser-lite.umd.production.min.js", | ||
"jsdelivr": "dist/bugsnag-browser-lite.umd.production.min.js", | ||
"jsnext:main": "dist/bugsnag-browser-lite.esm.js", | ||
"types": "./dist/index.d.ts", | ||
@@ -12,3 +17,3 @@ "files": [ | ||
"test": "jest", | ||
"build": "tsc" | ||
"build": "rimraf dist/ && tsdx build --name bugsnag-browser-lite --format esm,cjs,umd" | ||
}, | ||
@@ -22,2 +27,4 @@ "keywords": [], | ||
"jest": "^25.3.0", | ||
"rimraf": "^3.0.2", | ||
"tsdx": "^0.13.1", | ||
"typescript": "^3.8.3", | ||
@@ -24,0 +31,0 @@ "xhr-mock": "^2.5.1" |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
132751
840.5%14
180%642
114.72%1
-50%19
Infinity%7
40%2
100%2
100%1
Infinity%