Send data to localhost impossible (on Android)

Your Setup:

Please describe your issue as precise as possible.

  • I am using Js script from a button in a table row
  • I am testing the Seatable screen on Android, on Chrome
  • I want to send data of the script, so data from the row, to a local native app on ‘localhost’ on a specific port , and I have a network error : the JS script cannot reach localhost , and there is no traffic recorded of my local native app (local server)
  • The same part of code has been tested on same terminal, in an web app written in React Js (of mine) and works
  • to debug on Android , I display the last state past in a column of the table (see screen shot) ,
  • I tested inside Chrome , ‘installed’ and not ‘installed (PWA)’ : same problem.
  • On the 2 apps : mine and SeaTable, Chrome ask for authorization

Code :

const urlRaw =  "http://127.0.0.1:9100";

const SendRawAndroid =async ( data ) => {
  //output.text("data in (Android) :"+ data); inutile
  await base.updateRow(table.name, row['_id'], { 'type_appareil':"debut SendRawAndroid" });
  const xhr = new XMLHttpRequest();
  xhr.open("POST", urlRaw, true);
  await base.updateRow(table.name, row['_id'], { 'type_appareil':"passage POST" });
  xhr.setRequestHeader("Connection", "close");
  xhr.timeout = 1500;
  await base.updateRow(table.name, row['_id'], { 'type_appareil':"passage timeout" });
  xhr.ontimeout = async () =>{ //affichage dans la colonne 
    await base.updateRow(table.name, row['_id'], { 'type_appareil':"ontimeout" });
  } //console.log("Envoi terminé (timeout)");
  xhr.onerror = async () =>  await base.updateRow(table.name, row['_id'], { 'type_appareil':"erreur xhr réseau" });
  xhr.send(data);
  await base.updateRow(table.name, row['_id'], { 'type_appareil':"envoi terminé" });
  return { status: 200, data: "OK" };
};

Error Messages:

The code stops on line :

xhr.onerror = async () => await base.updateRow(table.name, row[‘_id’], { ‘type_appareil’:“erreur xhr réseau” });

Questions :

  • Is there a blocking code/parameter in the whole Seatable app against a localhost call ?
  • do you think to another solution to this issue please ?

Thank you

Hello,

The behavior you see is most likely not caused by SeaTable itself. In Android Chrome, 127.0.0.1 / localhost always refers to the Android device itself, not your PC or another machine on the network. So if your native app/server is running on your desktop, the SeaTable script running in the browser on Android will not be able to reach it via http://127.0.0.1:9100.

A few things to check:

  1. Use the machine’s LAN IP instead of localhost
    For example, try:

    const urlRaw = "http://192.168.1.50:9100";
    

    where 192.168.1.50 is the IP address of the machine running your local app.

  2. Make sure the server listens on a reachable interface
    It should bind to 0.0.0.0 or the LAN IP, not only to 127.0.0.1.

  3. Check CORS / browser security
    Since this request is made from the SeaTable web app in Chrome, your local server must allow the SeaTable origin, and HTTPS/mixed-content restrictions may also apply depending on how SeaTable is loaded.

  4. Confirm whether the target service is actually running on the Android device
    If you really want to use 127.0.0.1, then a service must be listening on the phone itself.

Thank you @daniel.pan , the problem is CORS. So I developed a proxy that push forward to the printer the load : I explain that on Impression d'étiquettes code barres depuis une app web lowcode ouverte à Javascript, comme Seatable