Skip to content

Doesn't work offline (<urlopen error [Errno -3] Try again>) #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rradar opened this issue Feb 18, 2019 · 12 comments
Closed

Doesn't work offline (<urlopen error [Errno -3] Try again>) #145

rradar opened this issue Feb 18, 2019 · 12 comments

Comments

@rradar
Copy link

rradar commented Feb 18, 2019

Hello,

I just read this one here on github:

And all the fancy JavaScript libraries are loaded from CDN (which means this does not work when you are offline).

Before I wrote this one here on a true home assistant offline environment.

Can't get this addon showing anything. The side asks for credentials - when entered it loads very long and doesn't show much (nothing rendered in browser - source code see down in this issue).

I think it's related to dependencies which are stored in the world wide web. (see hassio addon log line with '<urlopen error [Errno -3] Try again>')

Is there any way to include all dependencies that this addon doesn't need internet? I don't see any reason that this would be necessary at all... maybe for phony home calls.. but... seriously? These libraries should be very static... and home assistant works great offline - the configurator should so too! 😃 👍

Bonus: serving the used libraries locally does speed up the page loading in any case (compared to cdn stored libraries) 🌟

Source code for empty site:

<!doctype html>
<html lang="en">
  <head>
    <link rel='preload' href='/frontend_es5/core-02537159.js' as='script'/>
    <link rel='preload' href='/static/fonts/roboto/Roboto-Regular.ttf' as='font' crossorigin />
    <link rel='preload' href='/static/fonts/roboto/Roboto-Medium.ttf' as='font' crossorigin />
    <meta charset="utf-8">
<link rel='manifest' href='/manifest.json' crossorigin="use-credentials">
<link rel='icon' href='/static/icons/favicon.ico'>
<meta name='viewport' content='width=device-width, user-scalable=no'>
<style>
  body {
    font-family: Roboto, sans-serif;
    -moz-osx-font-smoothing: grayscale;
    -webkit-font-smoothing: antialiased;
    font-weight: 400;
    margin: 0;
    padding: 0;
    height: 100vh;
  }
</style>

    <title>Home Assistant</title>
    <link rel='apple-touch-icon' sizes='180x180'
          href='/static/icons/favicon-apple-180x180.png'>
    <link rel="mask-icon" href="/static/icons/mask-icon.svg" color="#03a9f4">
    <meta name='apple-mobile-web-app-capable' content='yes'>
    <meta name="msapplication-square70x70logo" content="/static/icons/tile-win-70x70.png"/>
    <meta name="msapplication-square150x150logo" content="/static/icons/tile-win-150x150.png"/>
    <meta name="msapplication-wide310x150logo" content="/static/icons/tile-win-310x150.png"/>
    <meta name="msapplication-square310x310logo" content="/static/icons/tile-win-310x310.png"/>
    <meta name="msapplication-TileColor" content="#03a9f4ff"/>
    <meta name='mobile-web-app-capable' content='yes'>
    <meta name='referrer' content='same-origin'>
    <meta name='theme-color' content='#03A9F4'>
    <style>
      #ha-init-skeleton::before {
        display: block;
        content: "";
        height: 112px;
        background-color: #03A9F4;
      }
    </style>
    <script>
      window.customPanelJS = '/frontend_es5/custom-panel-44491550.js';
      window.noAuth = '1';
      window.useOAuth = '1'
      window.Polymer = {
        lazyRegister: true,
        useNativeCSSProperties: true,
        dom: 'shadow',
        suppressTemplateNotifications: true,
        suppressBindingNotifications: true,
      };
    </script>
  </head>
  <body>
    <home-assistant>
      <div id='ha-init-skeleton'></div>
    </home-assistant>
    
      <script src="/static/custom-elements-es5-adapter.js"></script>
      <script src="/frontend_es5/compatibility-7e9ba135.js"></script>
    
    <script>
      var webComponentsSupported = (
        'customElements' in window &&
        'content' in document.createElement('template'));
      if (!webComponentsSupported) {
        (function() {
          var e = document.createElement('script');
          e.src = '/static/webcomponents-bundle.js';
          document.write(e.outerHTML);
        }());
      }
    </script>
    <script src='/frontend_es5/core-02537159.js'></script>
    <script src='/frontend_es5/app-1bf2cc89.js'></script>
    <script src='/frontend_es5/hass-icons-e5fe103b.js' async></script>
    </body>
</html>

And tha hassio addon log:

INFO:2019-02-18 14:21:06,164:__main__:Requesting authorization
INFO:2019-02-18 14:21:06,166:__main__:192.168.0.xxx - "GET / HTTP/1.1" 401 -
INFO:2019-02-18 14:21:09,185:__main__:192.168.0.xxx - "GET / HTTP/1.1" 200 -
WARNING:2019-02-18 14:21:14,564:__main__:Exception getting release
WARNING:2019-02-18 14:21:14,565:__main__:<urlopen error [Errno -3] Try again>
@danielperna84
Copy link
Owner

That's simply a design decision I have made. The configurator is completly contained within one single (~5000 lines of code) Python script for easy installation. No dependencies, no complex directory structures, and a simple embedded webserver.

When I started with the configurator I just wanted users to do a wget https...blablabla...configurator.py and then they're done. Having to fetch additional libraries, placing them in the correct directories and making sure all permissions are set correctly would be too much for average users to handle. Hence external dependencies that always work (when online).

Therefore: working as designed. And this will not change, because including all those libraries (and even images) in that one script will make the script even more huge and bloated. That's just not worth the effort. 😉

@rradar
Copy link
Author

rradar commented Feb 21, 2019

To bad, to sad. Wanted really to try your software...

Actually I'm using the hassio addon - so there is no difference between one or many files at all..

For people who are concerned about privacy all these external resources hosted by a few CDN's is a nightmare anyways. They provide the technical solution to track you over the whole web... and bloated for me is a website that need's to connect to more than one domain and is slowing down rendering the page because of this unnecessary connections.

Even google (with one of the biggest and fastest cdn's out there) is slowing down the web in a horrible way:

He found that the Javascript code helping Google place ads on pages and analyse user activity bestowed the longest delays on visitors. […] If used together on a site, these can add more than two-thirds of a second to loading times, he found.

Source: https://www.bbc.com/news/technology-47252725

I tried decentraleyes (https://decentraleyes.org/), a local cdn emulation. But your software still don't work/render (the used libraries probably aren't locally delivered with this browser addon).

Anyway - your project, your decisions. Thank's for doing this and have it open source! As it probably useful for many people (just not for me right now)! Could you just do me a last favor and list the used (external) libraries? Maybe there is a way... 😃

@danielperna84
Copy link
Owner

@rradar
Copy link
Author

rradar commented Feb 23, 2019

https://git.synz.io/Synzvato/decentraleyes/issues/345 👐

@danielperna84
Copy link
Owner

I had another look at the code. I thought the urlopen error would be caused by fetching which is the latest release. But the code already catches exceptions in those cases. So the error has to be caused by something else. Does the log provide more information? Maybe a traceback with the relevant lines in the code? Apart from the version-info the configurator itself should not try to access any other resources. Only the client has to be onle with access to the CDNs.

@rradar
Copy link
Author

rradar commented Feb 26, 2019

hi @danielperna84
thank's for the feedback. The whole log I see in the hassio addon page is in the issue. I don't have more logs. Is there any special location to get logs or traceback from hass-configurator (I'm in a hassio offline environment)?

Problem is that not only the server (hass[io] with hass-configurator) is offline but also the client due to no network connections available at all.

Thomas Rientjes suggested, https://git.synz.io/Synzvato/decentraleyes/issues/345#note_4281

In my opinion, it would be best to [...] write a CDN-link replacement script.

But thru lack of skills (and network connections) this is sadly not possible for me.

Would it be possible to have a option in hass-configurator to serve the libraries locally instead via CDN? So that it would work like now for anybody with internet connections but have a option (which would be activated manually) to store the libraries on the (hass[io]) server and serve them to the clients?

@danielperna84
Copy link
Owner

Is there any special location to get logs or traceback from hass-configurator (I'm in a hassio offline environment)?

Nevermind. It actually says in the log that the problem is with the release. It's just a warning though, so as said before, that message has no impact on functionality.

I think the best solution for you would simply be to use the IDE Add-on instead of the configurator. Even though your request is valid, it's too much effort to implement this for less than 1% of users who would benefit from this. Especially if another project already solves the issue.

@rradar
Copy link
Author

rradar commented Mar 2, 2019

I think the best solution for you would simply be to use the IDE Add-on instead of the configurator.

Thank's! I didn't know that this one exists! Solves all my problems! 🔝

@Misiu
Copy link

Misiu commented Oct 8, 2019

@danielperna84 like @rradar I was searching for an option to use Configurator in an offline environment. Because of the CDN resources the add-on won't work. I'm aware that you wanted a simple wget install, but as @rradar wrote, without CDN everything will work faster.

IDE Add-on is an option, but I really like Configurator, I don't need the whole IDE with projects, console, etc. Your add-on is ideal and many users will choose it because it is simple, intuitive and does it work just fine.

Please reconsider removing CDN's. I'm sure there is an option to wget an installer that will download everything needed.

This is the issue I created: home-assistant/addons#760

@danielperna84
Copy link
Owner

danielperna84 commented Oct 20, 2019

@Misiu
I now have a branch with the goal of adding offline-support: https://github.com/danielperna84/hass-configurator/tree/offline

But there's one big problem: some of these libraries reference hosted resources. Ace editor has many files regarding language support that would need to be included, and the css points to various fonts. All in all this is a lot of work, which includes modifying the libraries to not point to hosted resources.

So far I have only started doing this for the packaged variant (the one that's also used in hassio). It would only work with that variant anyways I guess. So, if you really want this, you can fork this repository, checkout the branch called offline, have a look what I have done there for jQuery and the configurators own css, and then do all that for the Ace editor, the css of Materialize (the fonts are missing). The Material Design Icons (also css + fonts) also have to be included. Basically anything that still points to hosted resources in any css or js file.

Edit:
Look at this commit for a smaller example on what to do.

@Misiu
Copy link

Misiu commented Oct 21, 2019

@danielperna84 thank You for that :)
I'd like to ask one more thing.
Your component is officially listed in HA and I think many people install it from there (I didn't know about pip way until I searched in Your repo), so do You still want to keep the whole component in one file?
I've recently started using HACS (https://github.com/custom-components/hacs) and there everything is split into separate files and folders. This makes things easier to maintain and develop.
Do You think everything could be split into individual parts? Similar to https://github.com/custom-components/hacs/tree/master/custom_components/hacs?

@danielperna84
Copy link
Owner

so do You still want to keep the whole component in one file?

In the mentioned branch you'll see, that I already have devided up the html and css into different files. So yes, for the pip-version (which the hassio-addon uses) this is an option. I don't know yet how to handle this for the single-file version. I am considering to not continue development on that one. The major features are available and there's not much to be done anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants