Why isn't my JavaScript code working?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Cogan

I’m using JavaScript.eval(start_code) in _ready to evaluate:

var input = document.createElement("input");
input.type = "file";
input.id = "fileImporter";
document.body.appendChild(input);
input.click();
:bust_in_silhouette: Reply From: klaas

Hi,
most browsers dont allow the fileInput to be clicked by script when it is not triggered by a user input event. Its a safety feature.
Everything else works just fine for me.

Since you seem to know about this kind of thing, is it possible to use an external JavaScript API? If not, I’m probably gonna have to build godot from scratch.

Cogan | 2021-08-27 23:16

Maybe you want to use the “File System Access API”

read about it here:
https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API
and here:
The File System Access API: simplifying access to local files - Chrome for Developers

But be aware, this API is currently in status “Working Draft”

klaas | 2021-08-29 11:12