Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
How can I monitor a JavaScript function of a site from the client?

I have a website. It uses vanilla JavaScript. I have access to all the client computers which use the site. My goal was to run a shell script prompted by a JavaScript function from the website. It is, of course, not possible for security reasons (a website accessing the computer's files while using it).

So my other idea: I want to create a software that somehow monitors the currently open website, and monitors if a certain function (which is known of course) was called, then this program can run a shell script.

Example: I have a function called IncomingCall() in JavaScript on my website. I want a software to be constantly running on the client computers and run example.sh if IncomingCall() is called. The website is on a server and the monitoring software and the shell script are on the client computers, which I have access to (no security hazard, no malicious intent).

So my question is, what language or technology could I use for this purpose, if this is possible at all, and how? I understand this is rather vague, but I have no clue how this could be done.

Edit: I want to run a shell script because I want to change the input of the TV connected to the computer to HDMI when a call is incoming on the site.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Since you have access to all clients you can run a local server on the every client. Using XMLHttpRequest in JavaScript you can connect to this server and send a HTTP request. When the server receives such a request it can execute the shell script.

Here is an simple example on how to run a server in Python. If you prefer an other language you can look for an other examples, there are a lot out there. Possibly even as a shell script, depending on which system you are running.

It is not possible in JavaScript by default to connect to the localhost if the site, who initiates the connection, is hosted on an other domain. You need to configure your local server to allow such an connection (Mozilla explanation). See example here in Python how to configure this.

Below is an example in JavaScript on how to initiate such an connection.

  let errFunc = async function (e) {
    alert("Could not connect to the server. Please check your internet connection");
  }

  let func = function (e) {
    if (this.status == 200) {
      alert("Succes");
    } else {
      alert("Error retrieving file '" + this.responseURL + "' from the server.");
    }
  }

    let req = new XMLHttpRequest();
    req.addEventListener("error", errFunc);
    req.addEventListener("timeout", errFunc);
    req.addEventListener("load", func);


  req.open("GET", "http://localhost/runScrip", true);
  req.send();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!