const text = 'Текст для сохранения';
const blob = new Blob([text], { type: 'text/plain' });
const content = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = content;
link.download = 'test.txt';
document.body.appendChild(link);
const click = new Event('click');
link.dispatchEvent(click);
link.remove();