I am trying to paste into the Gmail Compose field where you input your email's body, and all that. So, here is the issue: I want to paste parsedBody in, but for some reason, the lines.slice(2).join('\n').trim(); is not being applied to the pasted text. However, what's being logged to the console in console.log(parsedBody); has the slicing and joining applied.
So, is this a bug with the navigator.clipboard.writeText API, or am I making a mistake here?
const responseContainer = document.getElementById('generated-response');
if (responseContainer.value.length === 0 || generatingResponse) return;
const view = composeView.getBodyElement();
view.innerHTML = `<div>${responseContainer.value.replace(/\n/g, '<br>')} ${view.innerHTML}</div>`;
mainView.close();
try {
const fullEmail = responseContainer.value;
const lines = fullEmail.split(/\r?\n|\r/);
const subjectPrefix = "Subject: ";
let parsedSubject = "";
if (lines[0].startsWith(subjectPrefix)) {
parsedSubject = lines[0].substring(subjectPrefix.length);
}
composeView.setSubject(parsedSubject);
const parsedBody = lines.slice(2).join('\n').trim();
console.log(parsedBody);
await navigator.clipboard.writeText(parsedBody);
} catch (error) {
console.log('Failed to copy to clipboard');
console.log(error);
}
I tried pasting in the parsedBody, and logging it too. What's being logged is completely different from the parasedBody being pasted.