guy icon indicating copy to clipboard operation
guy copied to clipboard

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

Open latot opened this issue 4 years ago • 4 comments

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!

latot avatar Mar 09 '21 22:03 latot

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 ...

manatlan avatar Mar 16 '21 07:03 manatlan

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 avatar Apr 01 '21 19:04 latot

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 avatar Apr 01 '21 20:04 latot

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?

latot avatar Apr 01 '21 20:04 latot