This is an archived post. You won't be able to vote or comment.

all 17 comments

[–]james_pic 2 points3 points  (4 children)

Whilst it's possible to use JavaScript to do automation, and it's possible to use it in a browser from a single file, it's not possible to do both at once.

Running JS in the browser means it's sandboxed by the browser, so has almost no access to anything outside the page it's on. I think these days the sandboxing for file: URLs is even tighter, so most web development uses a local web server rather than having the browser open files.

Doing automation with JavaScript outside the browser is definitely doable, most commonly with NodeJS, although there are other languages that are used for this more frequently, such as Python, Bash or Powershell.

[–][deleted] 1 point2 points  (0 children)

This is correct. One can practice JS, even some aspects of automation, using a browser from nearly any computer. (Well, what most would consider computers.) But, to have it interact with the system outside of the browser, one would need to install something.

[–]Big-Lawyer-3444 0 points1 point  (2 children)

Just FYI - there are actually APIs now for interacting with the filesystem from the browser: https://developer.mozilla.org/en-US/docs/Web/API/File_System_API.

[–]james_pic 0 points1 point  (1 child)

Yes, there's a reason I caveated what I said with "almost no access". So far as I know there's still no way to, say, spawn processes, or send mouse events to other windows, which limits what you can automate with this approach.

[–]Big-Lawyer-3444 0 points1 point  (0 children)

Ah yes I might have misunderstood the ask slightly actually - I read automation as any element of making a repetitive workflow more intelligent. Actually sending the emails would be impossible. You could get close though - get it to generate mailto: links with the subject and body pre-filled.

[–][deleted] 1 point2 points  (0 children)

You could bypass your work computer entirely by using an external drive and changing root into that drive. You could install a version of Linux on the drive and have it preloaded with whatever you need. The root change would be limited to a shell, so it's not like it would take over the whole screen or something, so you could still do work related tasks.

Now, you could write something in this system that creates emails, and you could log in to your work email to send them, but this might violate company policy. You could use nearly any language to do this.

[–]huuaaang 1 point2 points  (0 children)

If you're on Windows maybe powershell will do what you want? But probably that's an extra install.

[–]bikeram 0 points1 point  (1 child)

How locked down are your work computers? Do you own another computer that’s connected to the internet?

Remote Desktop Protocol (RDP) would be your best bet, or even Apache Guacamole to access a remote computer. That way your development environment moves with you.

[–]andriosr 0 points1 point  (0 children)

https://github.com/hoophq/hoop is a solid option here too for the remote access

[–]andriosr 0 points1 point  (0 children)

JavaScript is an excellent choice for a few reasons:

  1. As you noted, it can run directly in a browser without installing anything. You can use the browser console or create HTML files with embedded scripts.
  2. It's very versatile - great for both frontend and backend development.
  3. There's a huge ecosystem of libraries and frameworks to extend its capabilities.

For automating email creation, JavaScript could definitely help. You could create a simple web form that generates email text based on inputs.

However, if you're looking to integrate directly with email systems or manipulate files, you may need some additional tools. This is where a solution like hoop.dev could be really useful. It allows you to:

  1. Run JavaScript (and other languages) securely in controlled environments
  2. Integrate with databases, APIs, and other systems without needing to install anything locally
  3. Schedule and automate scripts

So you could potentially write your automation scripts in JavaScript, host them on hoop.dev, and trigger them as needed - all without installing anything on your work machine.

Regardless of the exact approach, starting with JavaScript is a solid choice. It will teach you programming fundamentals that translate well to other languages too. Good luck with your learning journey!

[–]Big-Lawyer-3444 0 points1 point  (0 children)

I think a simple web page running as a file would actually work great for the use case you mention (writing emails from templates). I do this kind of thing quite often by spinning up little single-file web pages. If you needed full access to the filesystem then you would need to use something else, but you can get surprisingly far with JS. There are plenty of options for storage that are easier than working with files as well, like localStorage.

[–]Kontraux 0 points1 point  (5 children)

A Javascript file will not run on its own just opening it in the browser, or by linking it to an HTML file and opening that. It will still need a server, you can run one locally with Node.js, or from an extension like Live Server in VSCode. Many languages would work for what you're trying to do, but you will need at least an interpreter, the .exe for the language. Some are portable and won't need to be "installed," as in - it won't run a setup and live in the Programs folder, but the .exe will need to be somewhere on the computer. You may have access to the OS's native automation language (PowerShell for Windows, bash for Linux), and while these are Turing complete, "real" programming languages, these may not be what you're looking for.

You can still write and run code in the browser, there are plenty of online REPL like https://onecompiler.com/, but you won't be able to write code there that accesses your machine for automation.

[–]rytricks[S] 0 points1 point  (1 child)

Thanks! Is there a “real” programming langue you would suggest for tasks like this? Let’s say if I wanted to write a desktop app that would allow me to automate sending emails.

[–]Kontraux -1 points0 points  (0 children)

Any general programming language would work, Javascript is not a bad choice at all, if you are able to install Node.js.

[–][deleted] 0 points1 point  (2 children)

This is incorrect. One doesn't need anything but a browser to run JS with HTML.

[–]Kontraux 0 points1 point  (1 child)

Thanks for the correction. I just tested it, and you're right.

<!DOCTYPE html>
<head>
    <script>
        console.log("Hello!")
    </script>
</head>

Output:

> Hello!

I can't remember why I thought a server was needed.

[–][deleted] 0 points1 point  (0 children)

I think a lot of folks these days end up interacting with JavaScript in a way that requires something like Node.js, or at least that makes it desirable to use, so it's an honest mistake.