You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When user comes to a specific area, I create an iframe and connect to it with penpal.
When user leaves that area, I destroy the connection and remove the iframe.
In this scenario, if user leaves the area before connection is established (it may take time due to network latency etc), connection promise is always resolved with an error logged in the console. This is nasty because from code perpective I do it right by calling connection.destroy() to let penpal know the connection is destroyed on purpose, so it's not an error and shouldn't be logged like that.
In order to hide the error, I have to eat all exceptions from connection.promise which potentially hides real connection problems.
Here is the code sample:
constpage=document.getElementById('page');constiframe=document.createElement('iframe');iframe.src='child.html';constconnection=Penpal.connectToChild({iframe,debug: true});page.appendChild(iframe);// Emulate cleanup happening when user is leaving the page.setTimeout(()=>{connection.destroy();page.removeChild(iframe);},0);
constconnection=Penpal.connectToChild({iframe,debug: true});connection.promise.catch(()=>{});// Ugly because it may hide real connection problems.page.appendChild(iframe);
Ideally connection promise shouldn't get rejected with a error if connection was destoryed by a user. It should just never resolve, same way as child methods work on a destroyed connection.
We should see this error only if connection was aborted by penpal (for instance, by iframe watcher).
The text was updated successfully, but these errors were encountered:
Hey @h15ter, thanks for logging the issue. I can see that being annoying. I'm going to leave this issue open because I'll probably change the behavior in the next major version.
In the meantime, could you do the connection.promise.catch(()=>{}); right before you destroy the connection?
Imagine the following common scenario:
In this scenario, if user leaves the area before connection is established (it may take time due to network latency etc), connection promise is always resolved with an error logged in the console. This is nasty because from code perpective I do it right by calling
connection.destroy()
to let penpal know the connection is destroyed on purpose, so it's not an error and shouldn't be logged like that.In order to hide the error, I have to eat all exceptions from connection.promise which potentially hides real connection problems.
Here is the code sample:
And here is the error logged in console:
Error in console
And here is the workaround I use:
Ideally connection promise shouldn't get rejected with a error if connection was destoryed by a user. It should just never resolve, same way as child methods work on a destroyed connection.
We should see this error only if connection was aborted by penpal (for instance, by iframe watcher).
The text was updated successfully, but these errors were encountered: