<commit_before>import Promise from 'promise-polyfill';
import { BaseNotifier } from './base_notifier';
import { windowFilter } from './filter/window';
import { instrumentConsole } from './instrumentation/console';
import { instrumentDOM } from './instrumentation/dom';
import { instrumentFetch } from './instrumentation/fetch';
import { instrumentLocation } from './instrumentation/location';
import { instrumentXHR } from './instrumentation/xhr';
import { INotice } from './notice';
import { IInstrumentationOptions, IOptions } from './options';

interface ITodo {
  err: any;
  resolve: (notice: INotice) => void;
  reject: (err: Error) => void;
}

export class Notifier extends BaseNotifier {
  protected offline = false;
  protected todo: ITodo[] = [];

  _ignoreWindowError = 0;
  _ignoreNextXHR = 0;

  constructor(opt: IOptions) {
    super(opt);

    if (typeof window === 'undefined') {
      return;
    }

    this.addFilter(windowFilter);

    if (window.addEventListener) {
      this.onOnline = this.onOnline.bind(this);
      window.addEventListener('online', this.onOnline);
      this.onOffline = this.onOffline.bind(this);
      window.addEventListener('offline', this.onOffline);

      this.onUnhandledrejection = this.onUnhandledrejection.bind(this);
      window.addEventListener('unhandledrejection', this.onUnhandledrejection);

      this._onClose.push(() => {
        window.removeEventListener('online', this.onOnline);
        window.removeEventListener('offline', this.onOffline);
        window.removeEventListener(
          'unhandledrejection',
          this.onUnhandledrejection
        );
      });
    }

    // TODO: deprecated
    if (this._opt.ignoreWindowError) {
      opt.instrumentation.onerror = false;
    }

    this._instrument(opt.instrumentation);
  }

  _instrument(opt: IInstrumentationOptions = {}) {
    opt.console = !isDevEnv(this._opt.environment);

    if (enabled(opt.onerror)) {
      // tslint:disable-next-line:no-this-assignment
      let self = this;
      let oldHandler = window.onerror;
      window.onerror = function abOnerror() {
        if (oldHandler) {
          oldHandler.apply(this, arguments);<commit_msg>Allow to disable console tracking for production<commit_after>import Promise from 'promise-polyfill';
import { BaseNotifier } from './base_notifier';
import { windowFilter } from './filter/window';
import { instrumentConsole } from './instrumentation/console';
import { instrumentDOM } from './instrumentation/dom';
import { instrumentFetch } from './instrumentation/fetch';
import { instrumentLocation } from './instrumentation/location';
import { instrumentXHR } from './instrumentation/xhr';
import { INotice } from './notice';
import { IInstrumentationOptions, IOptions } from './options';

interface ITodo {
  err: any;
  resolve: (notice: INotice) => void;
  reject: (err: Error) => void;
}

export class Notifier extends BaseNotifier {
  protected offline = false;
  protected todo: ITodo[] = [];

  _ignoreWindowError = 0;
  _ignoreNextXHR = 0;

  constructor(opt: IOptions) {
    super(opt);

    if (typeof window === 'undefined') {
      return;
    }

    this.addFilter(windowFilter);

    if (window.addEventListener) {
      this.onOnline = this.onOnline.bind(this);
      window.addEventListener('online', this.onOnline);
      this.onOffline = this.onOffline.bind(this);
      window.addEventListener('offline', this.onOffline);

      this.onUnhandledrejection = this.onUnhandledrejection.bind(this);
      window.addEventListener('unhandledrejection', this.onUnhandledrejection);

      this._onClose.push(() => {
        window.removeEventListener('online', this.onOnline);
        window.removeEventListener('offline', this.onOffline);
        window.removeEventListener(
          'unhandledrejection',
          this.onUnhandledrejection
        );
      });
    }

    // TODO: deprecated
    if (this._opt.ignoreWindowError) {
      opt.instrumentation.onerror = false;
    }

    this._instrument(opt.instrumentation);
  }

  _instrument(opt: IInstrumentationOptions = {}) {
    if (opt.console === undefined) opt.console = !isDevEnv(this._opt.environment);

    if (enabled(opt.onerror)) {
      // tslint:disable-next-line:no-this-assignment
      let self = this;
      let oldHandler = window.onerror;
      window.onerror = function abOnerror() {
        if (oldHandler) {
          oldHandler.apply(this, arguments);
{'fraction_non_alphanumeric': 0.12821670428893905, 'fraction_numerical': 0.0009029345372460496, 'mean_word_length': 3.4848178137651824, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3691675', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1278, 'n_words': 260}