idle-js
idle-js copied to clipboard
Iframe support
I tried this library out. It is great, but I need a way to listen to click/keypress events on an iframe as well.
I was able to hack it to get iframes to work:
idle.settings.events.forEach(event => {
iframe.contentWindow.addEventListener(event, idle.idlenessEventsHandler)
});
I'm sure this could easily be a flag or 'querySelector' driven config.
e.g. targetIframes: ['#myframe']
fwiw, I ran the code above after the iframe was loaded, so that might be a reasonable assumption
Hello, It's a nice improvement. I would be happy to know more about the use case.
My users interact with inner iframes and I want to be able to detect click and mouse interaction inside the iframe as well as outside it. I'm using this to keep a user's login alive when they are not idle.
ok ! Made minor changes but might impact your project if you support IE11. Will publish on npm this updated version, mostly because it is lighter and I'd like to add the two features you suggested.
thanks for doing this. I'm fine with my workarounds for now, but I hope this helps others in the future.
Note: This addEventListener will only catch iframes events which share the same origin.
PS: You might need to watch via mutationObserver for new iframe elements.