Accessing external programs or urls with javascript

I am trying to dynamically load a new sentence for a word a of a language learning flashcard.

I was thinking of calling a local or a remote LLM for this task. I wasn’t able to find how to call a system command, so I went for the second option.

Below my attempt at a front template to fetch a url. It updates the div block with an empty string, are http requests blocked?

<div id="front">Loading…</div>
<div id="debug">start</div>

<script>
const http = new XMLHttpRequest();
const url='http://ifconfig.co/ip';

http.open("GET", url);
http.send();

http.onreadystatechange = (e) => {
  document.getElementById('front').innerHTML = http.responseText;
  document.getElementById('debug').innerHTML = 'loaded';
}
</script>

I understand the ability to use javascript is not well supported.

Probably CORS issues: Cross-Origin Resource Sharing (CORS)

This is not something specific to Anki. It’s a standard web security feature in browsers.

Accessing system commands from templates is also not possible for security reasons.

I see. I’m not surprised at the security measure regarding system commands.

In consequence, it seems there is no way to talk to the outside world from an Anki template? Which actually sounds reasonable.

Yes, unless if the website allows it, or you write a custom add-on to act as a proxy.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.