<file_sep>export declare const getResourceTiming: () => PerformanceEntry[];
<file_sep>export default function objectToFormData(obj: object) {
  const formdata = new FormData()
  Object.keys(obj).forEach(key => {
    formdata.append(key, JSON.stringify(obj[key]))
  })

  return formdata
}
<file_sep>export interface ICreateInspectorConfig {
    server: string;
    appId: string;
}
export declare const beaconApi: {
    performanceTiming: string;
};
export default function createInspector(inspectorConfig: ICreateInspectorConfig): void;
<file_sep># inspector
# inspector
<file_sep>export const getResourceTiming = () => {
  return performance.getEntriesByType('resource').filter(item => {
    if (item.name.includes('monitor_ignore=true')) {
      return false
    }

    return true
  })
}
<file_sep>export { default as createInspector } from './create-inspector';
<file_sep>import { createEventHandler } from './push-event'
import { getNavigationTiming } from './utils/get-navigation-timing'
import { getResourceTiming } from './utils/get-resource-timing'

export interface ICreateInspectorConfig {
  server: string
  appId: string
}
export default function createInspector(inspectorConfig: ICreateInspectorConfig) {
  const { server, appId } = inspectorConfig

  const eventHandler = createEventHandler(server, appId)

  const nativeError = console.error
  console.error = (message, ...restOptions) => {
    nativeError(message, ...restOptions)
    eventHandler.push('error', {
      type: 'console_error',
      message,
    })
  }
  const nativeWarn = console.warn
  console.warn = (message, ...restOptions) => {
    nativeWarn(message, ...restOptions)
    eventHandler.push('error', {
      type: 'console_error',
      message,
    })
  }
  window.addEventListener('unhandledrejection', function(e) {
    const { message, stack } = e.reason
    eventHandler.push('error', {
      type: 'promise_error',
      message,
      stack,
    })
  })
  window.addEventListener(
    'error',
    event => {
      const { message, filename, lineno, colno, error } = event
      eventHandler.push('error', {
        type: 'window_error',
        message,
        filename,
        lineno,
        colno,
        stack: error.stack,
      })
    },
    true
  )

  window.onload = () => {
    eventHandler.push('nav_timing', getNavigationTiming())
    eventHandler.push('resource_timing', getResourceTiming())
  }
}
<file_sep>export declare const getNavigationTiming: () => PerformanceTiming | PerformanceEntry;
<file_sep>export interface ICreateInspectorConfig {
    server: string;
    appId: string;
}
export default function createInspector(inspectorConfig: ICreateInspectorConfig): void;
<file_sep>export function createEventHandler(server: string, appId: string) {
  return {
    push: (name: string, payload: object) => {
      const beaconData = new FormData()

      beaconData.append('appId', appId)
      beaconData.append('name', name)
      beaconData.append('record', JSON.stringify(payload))
      beaconData.append('timestamp', String(Date.now()))

      navigator.sendBeacon(server + '/beacon?monitor_ignore=true', beaconData)
    },
  }
}
<file_sep>export default function objectToFormData(obj: object): FormData;
<file_sep>export const getNavigationTiming = () => {

  // experimental API, IE is not supported
  const navigationPf = window.performance.getEntriesByType('navigation')
  if (navigationPf.length) {
    return navigationPf[0]
    // if not supported, use timing api.
  } else return window.performance.timing
}
<file_sep>export declare function createEventHandler(server: string, appId: string): {
    push: (name: string, payload: object) => void;
};
