gluon-framework / gluon

A new framework for creating desktop apps from websites, using system installed browsers and NodeJS
https://gluonjs.org
MIT License
3.1k stars 76 forks source link

HTTPS required for gluon apps? #58

Closed boblund closed 1 year ago

boblund commented 1 year ago

Hi,

I have a web app that accesses a JSON API over http. It work fine in Chrome. When I try it with gluon I get this error

image

The app serving the JSON API doesn't use HTTPS and I have no control over that. Is this a gluon restriction? Can it be by by-passed?

Thanks, Bob

CanadaHonk commented 1 year ago

Could you please send the Gluon code you're using?

boblund commented 1 year ago

Hi,

It's the gluworld index.js loading a different index.html

import * as Gluon from '@gluon-framework/gluon';

(async () => {
  const browsers = process.argv.slice(2).filter(x => !x.startsWith('-'));

  if (browsers.length > 0) { // use argv as browsers to use
    for (const forceBrowser of browsers) {
      await Gluon.open('../owntonePled/index.html', {
        windowSize: [ 800, 500 ],
        forceBrowser
      });
    }

    return;
  }

  await Gluon.open('../../owntonePled/index.html', {
    windowSize: [ 800, 500 ]
  });
})();

Here's the code that makes the HTTP request

function curl(cmd, method='GET', headers={}, body='') {
    return new Promise((resolve, reject) => {
        const http = new XMLHttpRequest();
        http.open(method, `${href}${cmd}`);
        http.send();
        http.onreadystatechange = function() {
            if(this.readyState === 4) {
                if(this.status === 200) {
                    resolve(http.responseText);
                } else {
                    reject(new Error('Failed to load page, status code: ' + this.status));
                }
            }
        };
    });
};
boblund commented 1 year ago

I tried the gluworld code with this:

await Gluon.open('http://localhost:3000', {
  allowHTTP: true,
  windowSize: [ 800, 500 ]
});

and my app works as expected. So, it seems the HTTP limitation is in the gluon backend that hosts my web app?

I also tried :

Gluon.open('../owntonePled/index.html', {
        windowSize: [ 800, 500 ],
        forceBrowser
}

and got

image

After clicking reload I get this console message:

file:///Users/blund/Documents/SW%20Development/gluon/examples/gluworld/node_modules/@gluon-framework/gluon/src/launcher/inject.js:64
        let oldUrl = history.entries[history.currentIndex - 1].url;
                                                               ^

TypeError: Cannot read properties of undefined (reading 'url') at file:///Users/blund/Documents/SW%20Development/gluon/examples/gluworld/node_modules/@gluon-framework/gluon/src/launcher/inject.js:64:64
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
CanadaHonk commented 1 year ago

Is any of your code using a .local URL? Also ensure that path in your code ../ is relative to your JS file, and that you're using the latest Gluon version.

CanadaHonk commented 1 year ago

Closing due to inactivity (and Discord should be used for support instead).