Skip to content

Commit

Permalink
because of some JS buggyness
Browse files Browse the repository at this point in the history
  • Loading branch information
mlantz committed Jun 24, 2024
1 parent 4dbc6c0 commit d1695a8
Showing 1 changed file with 39 additions and 29 deletions.
68 changes: 39 additions & 29 deletions src/GrafiteMissionControlLaravelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,38 +44,48 @@ public function boot()
$logJSErrors = config('mission-control.log_javascript_errors', false);
$logTraffic = config('mission-control.log_traffic', true);

$script = <<<JS
if (${logTraffic}) {
window.addEventListener('load', () => {
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 = <<<JS
window.addEventListener('load', () => {
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 = <<<JS
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"
}));
return false;
});
JS;
}

return false;
});
}
$script = <<<JS
${logTrafficScript}
${logJSErrorsScript}
window.addEventListener('load', () => {
const pageEnd = window.performance.mark('pageEnd');
Expand Down

0 comments on commit d1695a8

Please sign in to comment.