diff --git a/src/GrafiteMissionControlLaravelProvider.php b/src/GrafiteMissionControlLaravelProvider.php index 243fa7b..9b23f43 100644 --- a/src/GrafiteMissionControlLaravelProvider.php +++ b/src/GrafiteMissionControlLaravelProvider.php @@ -44,38 +44,48 @@ public function boot() $logJSErrors = config('mission-control.log_javascript_errors', false); $logTraffic = config('mission-control.log_traffic', true); - $script = << { - const xhttp = new XMLHttpRequest(); - xhttp.open("POST", "${url}/api/webhook/${uuid}/traffic?key=${key}", true); - xhttp.setRequestHeader("Content-Type", "application/json; charset=UTF-8"); - xhttp.send(JSON.stringify({ - "referrer": document.referrer, - "pathname": window.location.pathname, - "hash": window.location.hash, - "search": window.location.search, - })); + $logJSErrorsScript = ''; + $logTrafficScript = ''; - return false; - }); -} + if ($logTraffic) { + $logTrafficScript = << { + const xhttp = new XMLHttpRequest(); + xhttp.open("POST", "${url}/api/webhook/${uuid}/traffic?key=${key}", true); + xhttp.setRequestHeader("Content-Type", "application/json; charset=UTF-8"); + xhttp.send(JSON.stringify({ + "referrer": document.referrer, + "pathname": window.location.pathname, + "hash": window.location.hash, + "search": window.location.search, + })); + + return false; +}); +JS; + } -if (${logJSErrors}) { - window.addEventListener('error', function (event) { - const xhttp = new XMLHttpRequest(); - xhttp.open("POST", "${url}/api/webhook/${uuid}/issue?key=${key}", true); - xhttp.setRequestHeader("Content-Type", "application/json; charset=UTF-8"); - xhttp.send(JSON.stringify({ - source: 'JavaScript', - message: `\${event.message}: on line \${event.lineno} at column \${event.colno} within \${event.filename}`, - stack: event.error.stack, - tag: "error" - })); + if ($logJSErrors) { + $logJSErrorsScript = << { const pageEnd = window.performance.mark('pageEnd');