As Osman Seah said, this cannot be done on the client side. You can create the file using Blob and URL.createObjectURL . But you cannot save the file, as this will cause big security problems.
, . , , PHP, ASP.NET Core...
Google Analytics, ( , ), API Google Analytics. Google Analytics API.
ga('send', {
hitType: 'event',
eventCategory: 'Error',
eventAction: window.location.href,
eventLabel: your_error_object
});