Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to detect if connection with child was lost?

See original GitHub issue


I am currently using penpal in a setup at a client but we stumbled upon the following “issue”:

When the original page in the iframe - that has the penpal library - is replaced by a page that does not have the library and we want to do a call to the child, we get this:

[Penpal] Parent: Sending getState() call

So Child has a function getState. Parent asks the child to do the getState function. This all works when the child has the library running, but we don’t get anything when that initial page is changed to another page. It just “hangs” on the “Sending <functionname> call”… No error, no disconnect, nothing.

The code we use is this from the parent to the child. We don’t see any Error from the catch. connection.current.promise .then((child) => { console.log(" Child doGetSTate ", child); return child .getState() .then((state) => console.log("save state to local storage ")) .catch((error) => console.log("an error occured in getState", error)); }) .catch((error) => console.log(" error occured in doGetState() ", error));

What are we doing wrong? TL;DR: we need to know how to intercept or detect when the connection with the child page is lost, so that we cannot do a call anymore to the child, because it just “hangs”: [Penpal] Parent: Sending getState() call



Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

Aaroniuscommented, Oct 12, 2020

Thanks for the feedback @yowainwright!

Aaroniuscommented, Sep 22, 2020

That’s where I was headed. It prompts a few questions:

  • Does onConnection get called on the initial connection and all subsequent connections, or just the subsequent connections?
  • What are the params to onConnection. Maybe the child object?
  • Should the child object provided through connection.promise stop functioning after a reconnection? Its API may be different than the newly-connected child API.
  • If onConnection is called on the initial connection and all subsequent connections, does that make onConnection redundant to connection.promise and should we therefore remove connection.promise?

I’m thinking it might be more appropriate to have onDisconnect (assuming this functionality is feasible) and onReconnect, where onReconnect only gets called on subsequent connections. On a reconnect, a new child object would get passed to the onReconnect callback and the child object provided through connection.promise would stop functioning (an error would be thrown if the parent attempts to call its methods).

I’m not in love with it though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Find Your Missing Child --- Top 5 Ways You Should ...
Way 2. Go to Missing People Website to Check Your Missing Child ... There are many websites that provide missing people information. You...
Read more >
What You Should Do When Your Child Is First Missing
Immediately report your child as missing to your local law enforcement agency. Ask investigators to enter your child into the National Crime Information...
Read more >
4 Habits that Disconnect You from Your Kids
Consider putting down your phone or taking a break from the computer screen to give your child your undivided attention. When they see...
Read more >
What to Do if Your Child Goes Missing
It is an essential tool in locating missing persons. Ask your local police to enter you child's name and information into the NCIC...
Read more >
Detect if Firebase connection is lost/regained
var firebaseRef = new Firebase(''); firebaseRef.child('.info/connected').on('value', function(connectedSnap) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found