I routinely have to verify links in Google Docs. This involves making sure the links are active, fact checking, ensuring the text of the link matches the title of the linked page, etc.
I'd like to write a script to open all the links in a document in a separate browser window, meaning in a single window that's separate from the document I'm working on rather than each in its own window.
ChatGPT gave me the following:
function openAllHyperlinks() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var links = body.getLinks();
for (var i = 0; i < links.length; i++) {
var url = links[i].getUrl();
window.open(url, '_blank');
}
}
However, I get the error:
TypeError: body.getLinks is not a function
Is this a much more complicated task than ChatGPT thinks it is, or am I missing something simple here?

As others have said, generated code isn't usually allowed here, and you definitely shouldn't rely on it if you don't have a firm grasp on what it's doing and feel comfortable modifying it yourself. Also, this is definitely a more complicated task than ChatGPT thinks it is. That being said, I like messing with Google Apps Script and decided to take a stab at it.
Firstly, the body object does not have a
getLinks()method, but you can cycle through the text to see if it has a link URL associated with it usinggetLinkUrl(). Then just add the URL to a Set if it isn't null.Actually opening the links is a bit more difficult, since you cannot open urls directly through GAS. You will need to create a modal dialog within the document, and create a small HTML page that contains a script to open the links.
Note: You will need to allow pop-ups on the document in order for this to work correctly.
Edit: I saw you mentioned that you tried it and it only opened one of the links. This is because you haven't allowed pop-ups on the page.