@grafana/faro-web-sdk
Version:
Faro instrumentations, metas, transports for web.
39 lines • 1.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CSPInstrumentation = void 0;
const faro_core_1 = require("@grafana/faro-core");
class CSPInstrumentation extends faro_core_1.BaseInstrumentation {
constructor() {
super();
this.name = '@grafana/faro-web-sdk:instrumentation-csp';
this.version = faro_core_1.VERSION;
}
initialize() {
document.addEventListener('securitypolicyviolation', this.securitypolicyviolationHandler.bind(this));
}
destroy() {
document.removeEventListener('securitypolicyviolation', this.securitypolicyviolationHandler);
}
securitypolicyviolationHandler(ev) {
// We must explicitly extract properties because SecurityPolicyViolationEvent
// properties are getters on the prototype chain, not own enumerable properties.
// Object.entries() would not capture them.
const attributes = {
blockedURI: ev.blockedURI,
columnNumber: ev.columnNumber,
disposition: ev.disposition,
documentURI: ev.documentURI,
effectiveDirective: ev.effectiveDirective,
lineNumber: ev.lineNumber,
originalPolicy: ev.originalPolicy,
referrer: ev.referrer,
sample: ev.sample,
sourceFile: ev.sourceFile,
statusCode: ev.statusCode,
violatedDirective: ev.violatedDirective,
};
this.api.pushEvent('securitypolicyviolation', (0, faro_core_1.stringifyObjectValues)(attributes));
}
}
exports.CSPInstrumentation = CSPInstrumentation;
//# sourceMappingURL=instrumentation.js.map