I've tried using JS's copy() and creating an element/populating it with the data/copying the result. I cannot figure out how to get the response.text() to the clipboard.
The actual fetch is an XHR but the below example should suffice:
fetch('/readme.txt')
.then(response => response.text())
.then(data => console.log(data));
You need to get response text and then copy it to the clipboard using another function:
fetch('/readme.txt').then(
response => response.text()
).then(
text => {
navigator.clipboard.writeText(text).then(
() => console.log("Success!"),
(err) => console.log("Error copying response text", err)
)
}
)
In old browsers navigator.clipboard can be unavailable, you can get more info about copying in this answer