diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 601f5414a..635d56fd9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,5 +42,14 @@ jobs: - name: npm install run: npm install + - name: Lint + uses: wearerequired/lint-action@v2 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + prettier: true + eslint: true + eslint_args: '--max-warnings 0' + eslint_extensions: js + - name: Run tests run: npm run test_ci diff --git a/.lgtm.yml b/.lgtm.yml index 061c733f4..e72db1933 100644 --- a/.lgtm.yml +++ b/.lgtm.yml @@ -1,8 +1,8 @@ path_classifiers: - generated: - - release - - dist - docs: - - examples - test: - - test + generated: + - release + - dist + docs: + - examples + test: + - test diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..f5e7ca462 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,18 @@ +.github +.next +.yalc +build +bundles +coverage +dist +lib +node_modules +out +public +release +vendor + +# ignore prettifying examples for now due to +# 1. there being minified snippets all over the place and +# 2. some tests fail cause they depend on some sources being exactly as they are +examples diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..9c5e96fe7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,39 @@ +{ + "[github-actions-workflow]": { + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true + }, + "[javascript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true + }, + "[javascriptreact]": { + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true + }, + "[json5]": { + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true + }, + "[jsonc]": { + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true + }, + "[typescript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true + }, + "[typescriptreact]": { + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true + }, + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true, + "editor.formatOnSaveMode": "file", + "editor.tabSize": 2, + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "explicit" + }, + "files.trimTrailingWhitespace": true, + "prettier.useEditorConfig": false +} diff --git a/CHANGELOG.md b/CHANGELOG.md index d1b9e8f98..d716945f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,6 @@ The change log has moved to this repo's [GitHub Releases Page](https://github.co The boolean configuration options `captureEmail` and `captureUsername` can be used to change this behaviour. - ## v2.3.6 - Updates for React Native @@ -46,26 +45,26 @@ The change log has moved to this repo's [GitHub Releases Page](https://github.co ## v2.3.2 -- Be defensive about navigator not existing on window -[#514](https://github.com/rollbar/rollbar.js/pull/514) +- Be defensive about navigator not existing on window + [#514](https://github.com/rollbar/rollbar.js/pull/514) -- Proper scrubbing -[#510](https://github.com/rollbar/rollbar.js/pull/510) +- Proper scrubbing + [#510](https://github.com/rollbar/rollbar.js/pull/510) -- Be defensive when accessing event properties -[#503](https://github.com/rollbar/rollbar.js/pull/503) +- Be defensive when accessing event properties + [#503](https://github.com/rollbar/rollbar.js/pull/503) - Add environment to options type enhancement -[#499](https://github.com/rollbar/rollbar.js/pull/499) + [#499](https://github.com/rollbar/rollbar.js/pull/499) -- call the transform in the options on the server side too -[#498](https://github.com/rollbar/rollbar.js/pull/498) +- call the transform in the options on the server side too + [#498](https://github.com/rollbar/rollbar.js/pull/498) -- fixes errMsg.match is not a function error -[#492](https://github.com/rollbar/rollbar.js/pull/492) +- fixes errMsg.match is not a function error + [#492](https://github.com/rollbar/rollbar.js/pull/492) -- Call callback even if logging same as last error -[#490](https://github.com/rollbar/rollbar.js/pull/490) +- Call callback even if logging same as last error + [#490](https://github.com/rollbar/rollbar.js/pull/490) ## v2.3.1 @@ -105,16 +104,20 @@ The change log has moved to this repo's [GitHub Releases Page](https://github.co - Fix some typescript declaration issues ## v2.2.7 + - Ensure scrubbing has the right value for telemetry inputs if `scrubTelemetryInputs` is true. - Fix memory leak related to network requests ## v2.2.6 + - Fix blacklist issue ## v2.2.5 + - Revert `isNative` check for replacing JSON functions ## v2.2.4 + - Fix a "race" condition in how wait works - Add two options to control scrubbing of telemetry input events: `scrubTelemetryInputs` and `telemetryScrubber`. @@ -126,9 +129,11 @@ The change log has moved to this repo's [GitHub Releases Page](https://github.co rather than an integer. ## v2.2.3 + - Actually make collecting network telemetry on by default ## v2.2.2 + - Fix bug in network telemetry that was wrapping onreadystatechage in correctly - Enable collecting network telemetry by default - Fix stack overflow issue due to scrubbing of self-referential objects @@ -137,43 +142,48 @@ The change log has moved to this repo's [GitHub Releases Page](https://github.co - Make the typescript type declarations better ## v2.2.1 + - Disable collection of network telemetry data by default ## v2.2.0 + - Telemetry data is now collected by default in the browser. See [README.md](https://github.com/rollbar/rollbar.js#telemetry) for information and configuration details. - Fix some typos in the typescript declarations ## v2.1.3 + - Actually change version number in package.json and build all relevant files ## v2.1.2 + - Actually send the client-side UUID with the item - Fix typos in typescript declaration ## v2.1.1 -- Allow more flexibility of request objects -[#346](https://github.com/rollbar/rollbar.js/pull/346) -- Address issue with handleItemWithError possible not calling the callback -[#345](https://github.com/rollbar/rollbar.js/pull/345) -- Fixed a typo in README.md -[#343](https://github.com/rollbar/rollbar.js/pull/343) -- unify configuration options -[#341](https://github.com/rollbar/rollbar.js/pull/341) -- add some intervals to keep the event loop running when wait is called -[#338](https://github.com/rollbar/rollbar.js/pull/338) -- [Fixes #336] Propagate message -[#337](https://github.com/rollbar/rollbar.js/pull/337) -- [Fixes #269] get rid of rollbar wrapper stack frames -[#335](https://github.com/rollbar/rollbar.js/pull/335) -- first pass at a typescript declaration file -[#334](https://github.com/rollbar/rollbar.js/pull/334) -- Fix #331 Verbose logging was using the wrong key structure -[#332](https://github.com/rollbar/rollbar.js/pull/332) +- Allow more flexibility of request objects + [#346](https://github.com/rollbar/rollbar.js/pull/346) +- Address issue with handleItemWithError possible not calling the callback + [#345](https://github.com/rollbar/rollbar.js/pull/345) +- Fixed a typo in README.md + [#343](https://github.com/rollbar/rollbar.js/pull/343) +- unify configuration options + [#341](https://github.com/rollbar/rollbar.js/pull/341) +- add some intervals to keep the event loop running when wait is called + [#338](https://github.com/rollbar/rollbar.js/pull/338) +- [Fixes #336] Propagate message + [#337](https://github.com/rollbar/rollbar.js/pull/337) +- [Fixes #269] get rid of rollbar wrapper stack frames + [#335](https://github.com/rollbar/rollbar.js/pull/335) +- first pass at a typescript declaration file + [#334](https://github.com/rollbar/rollbar.js/pull/334) +- Fix #331 Verbose logging was using the wrong key structure + [#332](https://github.com/rollbar/rollbar.js/pull/332) ## v2.1.0 + - Use the upstream version of console-polyfill: [#306](https://github.com/rollbar/rollbar.js/pull/306) - The verbose option still existed but didn't do anything, this adds back the functionality to output some information to the console: [#311](https://github.com/rollbar/rollbar.js/pull/311) @@ -197,10 +207,12 @@ The change log has moved to this repo's [GitHub Releases Page](https://github.co match what we allow in the browser: [#329](https://github.com/rollbar/rollbar.js/pull/329) ## v2.0.4 + - Fixes a small typo in the unhandled rejection handler. (pr#303) -- Updated the no-conflict example to use the new noconflict bundle and updated docs. +- Updated the no-conflict example to use the new noconflict bundle and updated docs. ## v2.0.3 + - Decreased NPM package size by removing examples and coverage directories. (pr#276) - Handle unordered params on the server side. (pr#286) - Fixes a server-side bug which failed to report an error if the request did not contain a `headers` key. (pr#288) @@ -210,13 +222,16 @@ The change log has moved to this repo's [GitHub Releases Page](https://github.co - Added a no-conflict bundle for the browser. (pr#295) ## v2.0.2 + - Added/updated docs on how to use rollbar.js with React, Angular 1 & 2, Ember, Backbone.js - Fixed a bug which was not respecting the `enabled` flag. (pr#280) ## v2.0.1 + - Maintenance release - No new features or bugfixes ## v2.0.0 + This release is the first where the library supports both browser and node environments from the same package. We decided to deprecate the `rollbar-browser` npm package in favor of using the `rollbar` npm package for all javascript environments. This single codebase now handles both @@ -247,6 +262,7 @@ be noticable. However, there are a few cases where one might run in to trouble. the convenience instance located at `window.Rollbar` will be setup as this handler. **v1.9.4** + - Updated to the newest version of console-polyfill (pr#244) - Log functions now return an object with the uuid as one of the keys (pr#236) - Fix issue related to Object.assign which caused problems on IE8 (pr#246) @@ -255,16 +271,20 @@ be noticable. However, there are a few cases where one might run in to trouble. `[object Object]` (pr#249) **v1.9.3** + - Serve rollbar.js from CDNJS **v1.9.2** + - Fix bug which would break `Rollbar.wrap()` if a string was thrown. (pr#222) **v1.9.1** + - Re-add rollbar.snippet.js to the Bower distribution. (pr#196) - This re-adds `dist/rollbar.snippet.js` to be backwards compatible with v1.8.5 **v1.9.0** + - Added support for arrays as custom data. (pr#194) - Documentation added for disabling Rollbar in the presence of ad blockers. (pr#190) - Added support for unhandled rejections from Promises. (pr#192) @@ -278,21 +298,27 @@ be noticable. However, there are a few cases where one might run in to trouble. - `src` **v1.8.5** + - Support retrying after being in offline mode. (pr#186) **v1.8.4** + - Check messages body for ignored messages. (pr#180) **v1.8.3** + - Fix a bug introduced in 1.8.0 where payload options were being removed by calls to `configure()`. (pr#176) **v1.8.2** + - Using the latest error-stack-parser from NPM. (pr#171) **v1.8.1** + - Changed the error-stack-parser dependency to use git+https. (pr#168) **v1.8.0** + - Fixed a few bugs in IE9, IE8 which were not recognozing `Error` instances properly. (pr#164) - Changed the behavior of `.global()` to only store options that we know how to process. (pr#164) - Refactored the code to remove custom polyfills. (pr#164) @@ -300,24 +326,30 @@ be noticable. However, there are a few cases where one might run in to trouble. - Fixed a bug in the jQuery plugin which would cause an error to be thrown in the internal `checkIgnore()` function. (pr#161) **v1.7.5** + - Fix bug when checking window.onerror.belongsToShim. **v1.7.4** + - Don't save shim's onerror when we are building globalnotifier. This fixes tests using window.onerror on a browser console - Fix Default endpoint on docs/configuration.md **v1.7.3** + - Added a named AMD module to the list of build targets. (pr#151) **v1.7.2** + - Bumped version so that NPM lists 1.7.2 as the latest, (was pointing to 1.6.0) (issue#148) **v1.7.1** + - Integrated karma tests. (pr#130) - Added warning message for common issue with `loadFull()` **v1.7.0** + - Fixed a bug that was not recognizing custom Error subclasses as valid errors. (pr#142) - Added documentation for the `hostWhiteList` option. (pr#138) - Changed the default uncaught error level to "error" instead of "warning". @@ -326,14 +358,17 @@ be noticable. However, there are a few cases where one might run in to trouble. asynchronously. This option is set to `true` by default. **v1.6.1** + - Updated bower.json to contain only a single .js entry. (issue#126) **v1.6.0** + - Fixed a bug that caused IE 8 to not properly initialize `window.Rollbar`. (pr#129) - Fixed the `XDomainRequest` code to work properly in IE 8. - Updated error parsing to provide more useful information for IE 8 errors **v1.5.0** + - Published rollbar.js to npmjs.com as rollbar-browser. (pr#127) - Fixes a bug where thrown non-error objects were not properly handled. (pr#125) - Fixes a bug that was logging an incorrect message when the notifier was disabled. (pr#124) @@ -341,158 +376,204 @@ be noticable. However, there are a few cases where one might run in to trouble. - Lots of code cleanup and smaller minified file size. **v1.4.4** + - Remove the `window.onload` event handler from the snippet and just create the script tag for the full rollbar.js source directly. (pr#120) **v1.4.3** + - Fixed a bug that would cause the notifier to crash when run in a Selenium test. (pr#117) - Force the notifier to always use HTTPS when communicating with api.rollbar.com. (pr#116) **v1.4.2** + - Fixed a bug that occurred in FF when Rollbar logged an internal error or if verbose mode was turned on. (pr#105) **v1.4.1** + - Fixed a bug that would load the wrong AMD module if a custom "rollbar" module was already defined. - Customers should copy and paste the new snippet into their code. **v1.4.0** + - Fix a bug, (introduced in v1.3) that caused Rollbar to generate an error when used with RequireJS. - Customers should copy and paste the new snippet into their code. **v1.3.0** + - Add more strict JSHint options and fix errors/warnings. **v1.3.0-rc.4** + - Fixes IE8 bug where JSON was not defined. **v1.3.0-rc.3** + - Remove polyfill. **v1.3.0-rc.2** + - Fix main values in bower.json. **v1.3.0-rc.1** + - Fixes for IE8+ **v1.3.0-alpha.5** + - Fix rollbar.umd.min.js URL in the snippet - Remove sourceMappingURL comment due to browser bug concerns **v1.3.0-alpha.4** + - Update CHANGELOG.md. **v1.3.0-alpha.3** + - Remove repeated timer to send enqueued payloads. - Change argument name in Stack() to fix uglify bug. -- Change __DEFAULT_ROLLBARJS_URL__ to use https. -- Set window._globalRollbarOptions when calling .configure(). +- Change **DEFAULT_ROLLBARJS_URL** to use https. +- Set window.\_globalRollbarOptions when calling .configure(). **v1.3.0-alpha.2** + - Update missing dist/ files. **v1.3.0-alpha.1** + - Build the library using webpack. - Replace tracekit and use error-stack-parser. **1.2.2** + - Added `nojson` distribution, for use on sites with a Content Security Policy that disallows `unsafe-eval`. (The standard distributions ship with a built-in JSON implementation, since external libraries, such as MooTools, sometimes break the brower's built-in JSON.) If you know that the built-in JSON is not being modified in your application, or you are disallowing `unsafe-eval`, use this distribution. **1.2.1** + - Fixed bug where the global notifier not being used to atch event listener exceptions. (pr#70) **1.2.0** + - Fixed AMD build to now return the notifier instance from the `init()` method. **1.1.16 - EDIT: This version has been removed due to finding a bug that broke backward compatibility.** + - Optimized the AMD build to not create a Notifier instance until the `init()` method is called. **1.1.15** + - Fix a bug where custom context functions that returned `undefined` were causing `Rollbar.wrap()` to throw an error. **1.1.14** + - Fix a bug in IE8 where DOMException was being used even though it's not defined, (#62). **1.1.13** + - Add `responseText` and `statusText` to the data reported by the jQuery ajax plugin, (pr#61). **1.1.12** + - Fixes a bug where `DOMException` objects were not recognized as error objects. (#55). **1.1.11** + - Fixes a bug where wrapped functions were crashing when a `null` callback was given to `removeEventListener()`, (pr#50). **1.1.10** + - Pulls in the latest JSON-js changes that do not call `.toJSON()` if the method exists already. This was breaking because MooTools v1.2.4 sets `.toJSON()` to use a broken JSON stringify implementation. **1.1.9** + - Always use the custom JSON implementation since some users are initializing a library that will overwrite a working `JSON.stringify()` with a broken one after Rollbar has checked for `JSON.stringify()` correctness. **1.1.8** + - Added a callback function to `loadFull()` to support Segment.io's plugin model. **1.1.7** + - Added `verbose` and `logFunction` options, (pr#42). **1.1.6** + - Added a `_wrappedSource` key to exceptions caught by the `wrap()` method to record the source of the wrapped function. **1.1.5** + - Added a `context` parameter to `Rollbar.wrap()`, (#26). - Added a `transform` option to allow the user to read/modify the payload before we send it to Rollbar, (#41 #43). **1.1.4** + - Added the `enabled` flag to determine when we should enqueue payloads to be sent, (#28). **1.1.3** + - Fixed a bug that was causing a stack overflow error in IE8, (#38). - Shaved off a few bytes from the snippet's size. **1.1.2** + - Fixed a bug that was causing `Rollbar.configure()` to incorrectly handle overwriting array configuration. - Added in support for a `ignoredMessages` configuration option, (pr#35). - Fixed a bug that was causing some `EventListener` objects to not be unbound, (pr#33). - Updated the snippet with fixes. **1.1.1** + - Fixed a bug with default rate limits. The defaults were not applied unless Rollbar.global() was called. **1.1.0** + - Add support for AMD JS loaders and refactor rollbar.require.js into rollbar.amd.js and rollbar.commonjs.js. **1.0.0-rc.11** + - Add support for whitelisting host names/domains, (pr#31). **1.0.0-rc.10** + - Add support for using rollbar with Webpack/Browserify via `require("rollbar.require.min.js")` with examples. **1.0.0-rc.9** + - Fixed a bug that caused a wrapped async handler to break if there was no callback provided. **1.0.0-rc.8** + - Fixed a bug that created/used a global variable. **1.0.0-rc.7** + - Change default reportLevel to `debug`. Previously, calls to `Rollbar.info` and `Rollbar.debug` were filtered out under the default configuration; now they are let through. **1.0.0-rc.6** + - Fixed a bug where items were sent in reverse order when queued - Add `maxItems` global option. If defined, at most this many items per pageview will be sent. Default `0`, meaning "no limit". **1.0.0-rc.5** + - Fix invalid payload generated when a non-Error object is passed as the error (#20) - Pass correct window.onerror args to original onerror (#23) - jQuery plugin: ignore status 0 events (#22) - Fix issue where callbacks to `.debug()`, etc. were not called if reportLevel filters the item (#24) **1.0.0-rc.4** + - Fix snippet in IE8 (change `map` to a for loop) **1.0.0-rc.3** + - Remove source maps from build process (no user-facing changes) **1.0.0-rc.2** + - Send access token as a request header in browsers that support XMLHttpRequest **1.0.0-rc.1** + - Fix bug where we were attempting to wrap an object instead of a function. - https://github.com/rollbar/rollbar.js/pull/17 - Fix bug in jQuery plugin that wasn't passing along the jQuery object. @@ -501,17 +582,21 @@ be noticable. However, there are a few cases where one might run in to trouble. - https://github.com/rollbar/rollbar.js/blob/master/docs/migration_v0_to_v1.md **1.0.0-beta9** + - Fix api response JSON parsing on older browsers **1.0.0-beta8** + - Fix uncaught errors being ignored in some browsers - Default uncaught error level now `warning` instead of `error`, also configurable - Wrap `addEventListener` to get more rich stack trace info for uncaught exceptions **1.0.0-beta7** + - Use a custom JSON.stringify method if the existing one does not work properly. **1.0.0-beta4** + - Fix some documentation bugs - Changes made to the snippet to put `environment` in the `payload` key. - Remove the default `context` value and associated logic around it being either a string or a function. @@ -519,4 +604,5 @@ be noticable. However, there are a few cases where one might run in to trouble. ## Upgrade Instructions ### v1.0.x to v1.1.x + 1. Replace your rollbar snippet with the latest from the [rollbar.js quickstart docs](https://rollbar.com/docs/notifier/rollbar.js/) or from [the GitHub repo](https://github.com/rollbar/rollbar.js/blob/master/dist/rollbar.snippet.js). diff --git a/Gruntfile.js b/Gruntfile.js index d64ca5660..5a12cffa6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -2,7 +2,6 @@ * Build and test rollbar.js */ - 'use strict'; var glob = require('glob'); @@ -12,7 +11,6 @@ var fs = require('fs'); var webpackConfig = require('./webpack.config.js'); - function findTests(context) { if (context !== 'browser') { return {}; @@ -20,7 +18,7 @@ function findTests(context) { var files = glob.sync('test/**/!(server.)*.test.js'); var mapping = {}; - files.forEach(function(file) { + files.forEach(function (file) { var testName = path.basename(file, '.test.js'); mapping[testName] = file; }); @@ -39,19 +37,19 @@ function buildGruntKarmaConfig(singleRun, tests, reporters) { pattern: 'dist/**/*.js', included: false, served: true, - watched: false + watched: false, }, { pattern: 'src/**/*.js', included: false, served: true, - watched: false + watched: false, }, { pattern: 'examples/**/*.js', included: false, served: true, - watched: false + watched: false, }, // Examples HTML, set `included: true`, but they won't be executed or added @@ -60,9 +58,9 @@ function buildGruntKarmaConfig(singleRun, tests, reporters) { pattern: 'examples/**/*.html', included: true, served: true, - watched: false - } - ] + watched: false, + }, + ], }, }; @@ -72,20 +70,18 @@ function buildGruntKarmaConfig(singleRun, tests, reporters) { for (var testName in tests) { var testFile = tests[testName]; - var testConfig = config[testName] = {}; + var testConfig = (config[testName] = {}); // Special case for testing requirejs integration. // Include the requirejs module as a framework so // Karma will inclue it in the web page. if (testName === 'requirejs') { - testConfig.files = [ - {src: './dist/rollbar.umd.js', included: false} - ]; + testConfig.files = [{ src: './dist/rollbar.umd.js', included: false }]; // NOTE: requirejs should go first in case the subsequent libraries // check for the existence of `define()` testConfig.frameworks = ['requirejs', 'expect', 'mocha']; } else { - testConfig.files = [{src: [testFile]}]; + testConfig.files = [{ src: [testFile] }]; } // Special config for BrowserStack IE tests @@ -98,8 +94,7 @@ function buildGruntKarmaConfig(singleRun, tests, reporters) { return config; } - -module.exports = function(grunt) { +module.exports = function (grunt) { require('time-grunt')(grunt); var browserTests = findTests('browser'); @@ -119,7 +114,6 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-text-replace'); grunt.loadNpmTasks('grunt-vows'); - var rollbarJsSnippet = fs.readFileSync('dist/rollbar.snippet.js'); var rollbarjQuerySnippet = fs.readFileSync('dist/plugins/jquery.min.js'); @@ -129,46 +123,62 @@ module.exports = function(grunt) { vows: { all: { options: { - reporter: 'spec' + reporter: 'spec', }, - src: ['test/server.*.test.js'] - } + src: ['test/server.*.test.js'], + }, }, karma: buildGruntKarmaConfig(singleRun, browserTests, reporters), replace: { snippets: { - src: ['*.md', 'src/**/*.js', 'examples/*.+(html|js)', 'examples/*/*.+(html|js)', 'docs/**/*.md'], + src: [ + '*.md', + 'src/**/*.js', + 'examples/*.+(html|js)', + 'examples/*/*.+(html|js)', + 'docs/**/*.md', + ], overwrite: true, replacements: [ // Main rollbar snippet { - from: new RegExp('^(.*// Rollbar Snippet)[\n\r]+(.*[\n\r])*(.*// End Rollbar Snippet)', 'm'), // eslint-disable-line no-control-regex - to: function(match, index, fullText, captures) { + from: new RegExp( + /* eslint-disable-next-line no-control-regex */ + '^(.*// Rollbar Snippet)[\n\r]+(.*[\n\r])*(.*// End Rollbar Snippet)', + 'm', + ), + to: function (match, index, fullText, captures) { captures[1] = rollbarJsSnippet; return captures.join('\n'); - } + }, }, // jQuery rollbar plugin snippet { - from: new RegExp('^(.*// Rollbar jQuery Snippet)[\n\r]+(.*[\n\r])*(.*// End Rollbar jQuery Snippet)', 'm'), // eslint-disable-line no-control-regex - to: function(match, index, fullText, captures) { + from: new RegExp( + /* eslint-disable-next-line no-control-regex */ + '^(.*// Rollbar jQuery Snippet)[\n\r]+(.*[\n\r])*(.*// End Rollbar jQuery Snippet)', + 'm', + ), + to: function (match, index, fullText, captures) { captures[1] = rollbarjQuerySnippet; return captures.join('\n'); - } + }, }, // README CI link { - from: new RegExp('(https://github\\.com/rollbar/rollbar\\.js/workflows/Rollbar\\.js%20CI/badge\\.svg\\?branch=v)([0-9a-zA-Z.-]+)'), - to: function(match, index, fullText, captures) { + from: new RegExp( + '(https://github\\.com/rollbar/rollbar\\.js/workflows/Rollbar\\.js%20CI/badge\\.svg\\?branch=v)([0-9a-zA-Z.-]+)', + ), + to: function (match, index, fullText, captures) { captures[1] = pkg.version; return captures.join(''); - } - } - ] - } - } + }, + }, + ], + }, + }, }); grunt.registerTask('build', ['webpack', 'replace:snippets']); @@ -176,12 +186,12 @@ module.exports = function(grunt) { grunt.registerTask('test', ['test-server', 'test-browser']); grunt.registerTask('release', ['build', 'copyrelease']); - grunt.registerTask('test-server', function(_target) { + grunt.registerTask('test-server', function (_target) { var tasks = ['vows']; grunt.task.run.apply(grunt.task, tasks); }); - grunt.registerTask('test-browser', function(target) { + grunt.registerTask('test-browser', function (target) { var karmaTask = 'karma' + (target ? ':' + target : ''); var tasks = [karmaTask]; grunt.task.run.apply(grunt.task, tasks); @@ -196,11 +206,11 @@ module.exports = function(grunt) { var minJs = 'dist/rollbar' + buildName + '.min.js'; var releaseJs = 'release/rollbar' + buildName + '-' + version + '.js'; - var releaseMinJs = 'release/rollbar' + buildName + '-' + version + '.min.js'; + var releaseMinJs = + 'release/rollbar' + buildName + '-' + version + '.min.js'; grunt.file.copy(js, releaseJs); grunt.file.copy(minJs, releaseMinJs); }); }); - }; diff --git a/README.md b/README.md index 2240f407c..61ad7be64 100644 --- a/README.md +++ b/README.md @@ -12,21 +12,20 @@ [![Code Quality: Javascript](https://img.shields.io/lgtm/grade/javascript/g/rollbar/rollbar.js.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/rollbar/rollbar.js/context:javascript) [![Total Alerts](https://img.shields.io/lgtm/alerts/g/rollbar/rollbar.js.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/rollbar/rollbar.js/alerts) - --- ## Key benefits of using Rollbar.js are: + - **Cross platform:** Rollbar.js supports both server-side and client-side Javascript, including frameworks such as React, Angular, Express, Next.js and more. - **Telemetry:** The telemetry timeline provides a list of “breadcrumbs” events that can help developers understand and fix problems in their client-side javascript. Learn more about telemetry. - **Automatic error grouping:** Rollbar aggregates Occurrences caused by the same error into Items that represent application issues. Learn more about reducing log noise. - **Advanced search:** Filter items by many different properties. Learn more about search. - **Customizable notifications:** Rollbar supports several messaging and incident management tools where your team can get notified about errors and important events by real-time alerts. Learn more about Rollbar notifications. - ## Setup Instructions 1. [Sign up for a Rollbar account](https://rollbar.com/signup). -2. For client-side Javascript, follow the [Browser Quick Start](https://docs.rollbar.com/docs/javascript#section-quick-start-browser) instructions. For Node.js, follow the [Server Quick Start](https://docs.rollbar.com/docs/javascript#section-quick-start-server). +2. For client-side Javascript, follow the [Browser Quick Start](https://docs.rollbar.com/docs/javascript#section-quick-start-browser) instructions. For Node.js, follow the [Server Quick Start](https://docs.rollbar.com/docs/javascript#section-quick-start-server). ## Usage and Reference diff --git a/bower.json b/bower.json index 3277d005f..1dcfc3c43 100644 --- a/bower.json +++ b/bower.json @@ -1,9 +1,7 @@ { "name": "rollbar", "dependencies": {}, - "main": [ - "dist/rollbar.umd.js" - ], + "main": ["dist/rollbar.umd.js"], "ignore": [ "dist/*.nojson*", "dist/*.named-amd*", diff --git a/defaults.js b/defaults.js index 5b79ee295..c11950703 100644 --- a/defaults.js +++ b/defaults.js @@ -5,13 +5,25 @@ var version = pkg.version; module.exports = { __NOTIFIER_VERSION__: JSON.stringify(pkg.version), __JQUERY_PLUGIN_VERSION__: JSON.stringify(pkg.plugins.jquery.version), - __DEFAULT_SERVER_SCRUB_FIELDS__: JSON.stringify(pkg.defaults.server.scrubFields), - __DEFAULT_SERVER_SCRUB_HEADERS__: JSON.stringify(pkg.defaults.server.scrubHeaders), + __DEFAULT_SERVER_SCRUB_FIELDS__: JSON.stringify( + pkg.defaults.server.scrubFields, + ), + __DEFAULT_SERVER_SCRUB_HEADERS__: JSON.stringify( + pkg.defaults.server.scrubHeaders, + ), __DEFAULT_ENDPOINT__: JSON.stringify(pkg.defaults.endpoint), __DEFAULT_LOG_LEVEL__: JSON.stringify(pkg.defaults.logLevel), __DEFAULT_REPORT_LEVEL__: JSON.stringify(pkg.defaults.reportLevel), - __DEFAULT_UNCAUGHT_ERROR_LEVEL: JSON.stringify(pkg.defaults.uncaughtErrorLevel), - __DEFAULT_ROLLBARJS_URL__: JSON.stringify('https://' + pkg.cdn.host + '/rollbarjs/refs/tags/v' + version + '/rollbar.min.js'), + __DEFAULT_UNCAUGHT_ERROR_LEVEL: JSON.stringify( + pkg.defaults.uncaughtErrorLevel, + ), + __DEFAULT_ROLLBARJS_URL__: JSON.stringify( + 'https://' + + pkg.cdn.host + + '/rollbarjs/refs/tags/v' + + version + + '/rollbar.min.js', + ), __DEFAULT_MAX_ITEMS__: pkg.defaults.maxItems, - __DEFAULT_ITEMS_PER_MIN__: pkg.defaults.itemsPerMin + __DEFAULT_ITEMS_PER_MIN__: pkg.defaults.itemsPerMin, }; diff --git a/docs/extension-exceptions.md b/docs/extension-exceptions.md index 906bc16f8..9b7517870 100644 --- a/docs/extension-exceptions.md +++ b/docs/extension-exceptions.md @@ -7,7 +7,7 @@ For most websites, the path for dealing with browser extension originating excep ## Dealing with adblockers -The most common type of extension that can be problematic is adblockers. These extensions can disable loading +The most common type of extension that can be problematic is adblockers. These extensions can disable loading certain external scripts or remove elements from a page based on a simple set of heuristics. You can see a [full example](https://github.com/rollbar/rollbar.js/tree/master/examples/extension-exceptions/) @@ -24,7 +24,7 @@ Load Rollbar.js as normal. captureUncaught: true, payload: { environment: 'development', - } + }, }; ``` @@ -33,45 +33,50 @@ Add an html element with "bait" class names to be removed by adblockers. ```html -
+ ``` Add functions to check for the presence and visibility of our bait div. ```js - function disableRollbar() { - Rollbar.configure({enabled: false}); - } - - function checkForAds() { - var bait = document.getElementById("blocker-bait"); +function disableRollbar() { + Rollbar.configure({ enabled: false }); +} - if (bait == null) { - disableRollbar(); - return; - } - - var baitStyles = window.getComputedStyle(bait); - if (baitStyles && ( - baitStyles.getPropertyValue('display') === 'none' || - baitStyles.getPropertyValue('visibility') === 'hidden')) { - disableRollbar(); - } - } +function checkForAds() { + var bait = document.getElementById('blocker-bait'); - function onLoadStartAdCheck() { - // Ad blockers generally execute just after load, let's delay ourselves to get behind it. - setTimeout(checkForAds, 1); + if (bait == null) { + disableRollbar(); + return; } - if (window.addEventListener !== undefined) { - window.addEventListener('load', onLoadStartAdCheck, false); - } else { - window.attachEvent('onload', onLoadStartAdCheck); + var baitStyles = window.getComputedStyle(bait); + if ( + baitStyles && + (baitStyles.getPropertyValue('display') === 'none' || + baitStyles.getPropertyValue('visibility') === 'hidden') + ) { + disableRollbar(); } +} + +function onLoadStartAdCheck() { + // Ad blockers generally execute just after load, let's delay ourselves to get behind it. + setTimeout(checkForAds, 1); +} + +if (window.addEventListener !== undefined) { + window.addEventListener('load', onLoadStartAdCheck, false); +} else { + window.attachEvent('onload', onLoadStartAdCheck); +} ``` -The above approach is likely to work in the majority of cases, *but it is not foolproof*. Extensions and their +The above approach is likely to work in the majority of cases, _but it is not foolproof_. Extensions and their behavior evolve over time and nothing stops a user from opening their console and modifying / executing code as well. A practical approach involves incrementally adjusting your detection as new exceptions occur in large numbers. diff --git a/docs/migration_v0_to_v1.md b/docs/migration_v0_to_v1.md index 2e4327123..48bb03c1a 100644 --- a/docs/migration_v0_to_v1.md +++ b/docs/migration_v0_to_v1.md @@ -7,19 +7,20 @@ ### Change the config object: ```js -var _rollbarParams = {"server.environment": "production"}; -_rollbarParams["notifier.snippet_version"] = "2"; var _rollbar=["POST_CLIENT_ITEM_ACCESS_TOKEN", _rollbarParams]; +var _rollbarParams = { 'server.environment': 'production' }; +_rollbarParams['notifier.snippet_version'] = '2'; +var _rollbar = ['POST_CLIENT_ITEM_ACCESS_TOKEN', _rollbarParams]; ``` -to +to ```js var _rollbarConfig = { - accessToken: "POST_CLIENT_ITEM_ACCESS_TOKEN", + accessToken: 'POST_CLIENT_ITEM_ACCESS_TOKEN', captureUncaught: true, payload: { - environment: "production" - } + environment: 'production', + }, }; ``` @@ -29,21 +30,21 @@ e.g. ```js var _rollbarParams = { - checkIgnore: function(msg, url, lineNo, colNo, error) { + checkIgnore: function (msg, url, lineNo, colNo, error) { // don't ignore anything (default) return false; }, - context: "home#index", + context: 'home#index', itemsPerMinute: 60, - level: "error", + level: 'error', person: { id: 12345, - username: "johndoe", - email: "johndoe@example.com" + username: 'johndoe', + email: 'johndoe@example.com', }, - "server.branch": "develop", - "server.environment": "staging", - "server.host": "web1" + 'server.branch': 'develop', + 'server.environment': 'staging', + 'server.host': 'web1', }; ``` @@ -51,28 +52,28 @@ should be changed to ```js var _rollbarConfig = { - accessToken: "POST_CLIENT_ITEM_ACCESS_TOKEN", + accessToken: 'POST_CLIENT_ITEM_ACCESS_TOKEN', captureUncaught: true, - checkIgnore: function(msg, url, lineNo, colNo, error) { + checkIgnore: function (msg, url, lineNo, colNo, error) { // don't ignore anything (default) return false; }, itemsPerMinute: 60, - logLevel: "error", + logLevel: 'error', payload: { - environment: "production", - context: "home#index", + environment: 'production', + context: 'home#index', person: { id: 12345, - username: "johndoe", - email: "johndoe@example.com" + username: 'johndoe', + email: 'johndoe@example.com', }, server: { - branch: "develop", - environment: "staging", - host: "web1" - } - } + branch: 'develop', + environment: 'staging', + host: 'web1', + }, + }, }; ``` @@ -80,7 +81,6 @@ var _rollbarConfig = { For the latest snippet, see the instructions here: [https://rollbar.com/docs/notifier/rollbar.js/](https://rollbar.com/docs/notifier/rollbar.js/). - ## Update references to `_rollbar.push()` The v1 notifier has a more intuitive interface for recording errors and generic logging. @@ -118,19 +118,18 @@ try { } ``` - ### Recording a log message From ```js -_rollbar.push("Some log message"); +_rollbar.push('Some log message'); ``` to ```js -Rollbar.info("Some log message"); +Rollbar.info('Some log message'); ``` #### Including custom data @@ -138,13 +137,17 @@ Rollbar.info("Some log message"); From ```js -_rollbar.push({level: "warning", msg: "Some warning message", point: {x: 5, y: 10}}); +_rollbar.push({ + level: 'warning', + msg: 'Some warning message', + point: { x: 5, y: 10 }, +}); ``` to ```js -Rollbar.warning("Some warning message", {point: {x: 5, y: 10}}); +Rollbar.warning('Some warning message', { point: { x: 5, y: 10 } }); ``` #### Using callbacks @@ -155,11 +158,11 @@ From try { doSomething(); } catch (e) { - _rollbar.push(e, function(err, uuid) { + _rollbar.push(e, function (err, uuid) { if (err !== null) { - console.error("Could not report an exception to Rollbar, error: " + err); + console.error('Could not report an exception to Rollbar, error: ' + err); } else { - console.log("Reported exception to Rollbar, uuid: " + uuid); + console.log('Reported exception to Rollbar, uuid: ' + uuid); } }); } @@ -171,11 +174,11 @@ to try { doSomething(); } catch (e) { - Rollbar.log(e, function(err, uuid) { + Rollbar.log(e, function (err, uuid) { if (err !== null) { - console.error("Could not report an exception to Rollbar, error: " + err); + console.error('Could not report an exception to Rollbar, error: ' + err); } else { - console.log("Reported exception to Rollbar, uuid: " + uuid); + console.log('Reported exception to Rollbar, uuid: ' + uuid); } }); } diff --git a/examples/angular2/angular.json b/examples/angular2/angular.json index 88b3a7c0d..3d993ee20 100644 --- a/examples/angular2/angular.json +++ b/examples/angular2/angular.json @@ -18,13 +18,8 @@ "main": "src/main.ts", "polyfills": "src/polyfills.ts", "tsConfig": "src/tsconfig.app.json", - "assets": [ - "src/favicon.ico", - "src/assets" - ], - "styles": [ - "src/styles.css" - ], + "assets": ["src/favicon.ico", "src/assets"], + "styles": ["src/styles.css"], "scripts": [], "es5BrowserSupport": true }, @@ -79,26 +74,16 @@ "polyfills": "src/polyfills.ts", "tsConfig": "src/tsconfig.spec.json", "karmaConfig": "src/karma.conf.js", - "styles": [ - "src/styles.css" - ], + "styles": ["src/styles.css"], "scripts": [], - "assets": [ - "src/favicon.ico", - "src/assets" - ] + "assets": ["src/favicon.ico", "src/assets"] } }, "lint": { "builder": "@angular-devkit/build-angular:tslint", "options": { - "tsConfig": [ - "src/tsconfig.app.json", - "src/tsconfig.spec.json" - ], - "exclude": [ - "**/node_modules/**" - ] + "tsConfig": ["src/tsconfig.app.json", "src/tsconfig.spec.json"], + "exclude": ["**/node_modules/**"] } } } @@ -124,13 +109,11 @@ "builder": "@angular-devkit/build-angular:tslint", "options": { "tsConfig": "e2e/tsconfig.e2e.json", - "exclude": [ - "**/node_modules/**" - ] + "exclude": ["**/node_modules/**"] } } } } }, "defaultProject": "my-app" -} \ No newline at end of file +} diff --git a/examples/angular2/e2e/protractor.conf.js b/examples/angular2/e2e/protractor.conf.js index 86776a391..98bba7090 100644 --- a/examples/angular2/e2e/protractor.conf.js +++ b/examples/angular2/e2e/protractor.conf.js @@ -5,11 +5,9 @@ const { SpecReporter } = require('jasmine-spec-reporter'); exports.config = { allScriptsTimeout: 11000, - specs: [ - './src/**/*.e2e-spec.ts' - ], + specs: ['./src/**/*.e2e-spec.ts'], capabilities: { - 'browserName': 'chrome' + browserName: 'chrome', }, directConnect: true, baseUrl: 'http://localhost:4200/', @@ -17,12 +15,14 @@ exports.config = { jasmineNodeOpts: { showColors: true, defaultTimeoutInterval: 30000, - print: function() {} + print: function () {}, }, onPrepare() { require('ts-node').register({ - project: require('path').join(__dirname, './tsconfig.e2e.json') + project: require('path').join(__dirname, './tsconfig.e2e.json'), }); - jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); - } -}; \ No newline at end of file + jasmine + .getEnv() + .addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); + }, +}; diff --git a/examples/angular2/e2e/src/app.e2e-spec.ts b/examples/angular2/e2e/src/app.e2e-spec.ts index 3b79f7c47..12ba22b16 100644 --- a/examples/angular2/e2e/src/app.e2e-spec.ts +++ b/examples/angular2/e2e/src/app.e2e-spec.ts @@ -16,8 +16,10 @@ describe('workspace-project App', () => { afterEach(async () => { // Assert that there are no errors emitted from the browser const logs = await browser.manage().logs().get(logging.Type.BROWSER); - expect(logs).not.toContain(jasmine.objectContaining({ - level: logging.Level.SEVERE, - } as logging.Entry)); + expect(logs).not.toContain( + jasmine.objectContaining({ + level: logging.Level.SEVERE, + } as logging.Entry), + ); }); }); diff --git a/examples/angular2/e2e/tsconfig.e2e.json b/examples/angular2/e2e/tsconfig.e2e.json index a6dd62202..22e04cb18 100644 --- a/examples/angular2/e2e/tsconfig.e2e.json +++ b/examples/angular2/e2e/tsconfig.e2e.json @@ -4,10 +4,6 @@ "outDir": "../out-tsc/app", "module": "commonjs", "target": "es5", - "types": [ - "jasmine", - "jasminewd2", - "node" - ] + "types": ["jasmine", "jasminewd2", "node"] } -} \ No newline at end of file +} diff --git a/examples/angular2/src/app/app-routing.module.ts b/examples/angular2/src/app/app-routing.module.ts index d425c6f56..11c2e8407 100644 --- a/examples/angular2/src/app/app-routing.module.ts +++ b/examples/angular2/src/app/app-routing.module.ts @@ -5,6 +5,6 @@ const routes: Routes = []; @NgModule({ imports: [RouterModule.forRoot(routes)], - exports: [RouterModule] + exports: [RouterModule], }) -export class AppRoutingModule { } +export class AppRoutingModule {} diff --git a/examples/angular2/src/app/app.component.html b/examples/angular2/src/app/app.component.html index b0c533d70..62e304ba1 100644 --- a/examples/angular2/src/app/app.component.html +++ b/examples/angular2/src/app/app.component.html @@ -1,8 +1,6 @@ -