Skip to content
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

Uncaught DOMException: An attempt was made to use an object that is not, or is no longer, usable #30

Open
latot opened this issue Mar 9, 2021 · 4 comments

Comments

@latot
Copy link

latot commented Mar 9, 2021

Hi hi, I'm starting to learn how to use this, sadly I don't have idea why this don't works, I try several things but still can't solve this, but is too similar to the minimal examples of the documentation...

<script src="guy.js"></script>
<body></body>
<script>
    list = self.elements()
</script>
#!/usr/bin/env python
from guy import Guy

class App(Guy):
  def elements(self):
      return ["test1", "test2"]
  
if __name__ == "__main__": 
    App().serve(open=False, autoreload=False)

Checking in the explorer, I get the next message:

Uncaught DOMException: An attempt was made to use an object that is not, or is no longer, usable App_7fb4fe74b940-js:140
    _call http://localhost:8000/App_7fb4fe74b940-js:140
    elements http://localhost:8000/App_7fb4fe74b940-js:192
    <anonymous > http://localhost:8000/:9

I'm using the latest version from pip3.

Thx!

@manatlan
Copy link
Owner

Hi ... you can't call directly a python method, because the client/html needs to wait for guy to establish the socket.
In your case, you will need to explicitly wait, and start the initialization with guy.init()

Like that :

<script src="guy.js"></script>
<body></body>
<script>
    async function test() {
        list = await self.elements()
        console.log(list)
    }
    
    guy.init( test )
</script>

guy.init will start the test method, when the socket will be ready ... (nearly immediatly)
and it will work like you expected ...

@latot
Copy link
Author

latot commented Apr 1, 2021

Hi, I don't know why, but i never get the mail with your answer, I really really would like to know this before, and really thank to let me know this :) I'll test all this now.

@latot
Copy link
Author

latot commented Apr 1, 2021

Hi hi, sadly is not working D:

I'm testing in this way:

<body style="display='none'">fuuuuuu fooooo</body>
<script>
    async function start() {
        await self.start()
        document.style.display=""
    }
    
    guy.init( start )
</script>

In my tests, there is some weird things.

First, If I start the start function manually after some time, it completes all in a few seconds and I can use the things.

If I use guy.init(start) takes a lot of time to start the function, and even more to finish, in all my runs, I still can't complete the start function.

How I know the function finish when I start it manually? because the start function load tables, and I can see them.

I don't know why start the function take soo much time..., I have overloaded the init function in this way:

    def __init__(self):
        Guy.__init__(self)
        ...do more things....

And the more things are pretty simple things, shouldn't take more than a few seconds...

I'm confused D:

@latot
Copy link
Author

latot commented Apr 1, 2021

Okey..., I found why this, here is weird thing, and not about the lib :D

If we refresh mozilla will do weird things, is like don't connect directly to the server, maybe try to use the cache or something, if I force to reload two time mozilla I get a message in python that I'm trying to connect, to force this I need to use the anonymous mode., With that, all works....

Maybe try from guy disable the cache?

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

2 participants