-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
It throw error if target element inside a iframe on Chrome #97
Comments
Hey @minhtranite thanks for the info. Looks easy enough to sort. Will look into it! |
This has another issue where the document has no listeners for observation, so the observation is only noticed when the scheduler is run in the main document. This could also be fixed with changes from #42 |
@minhtranite as a workaround for now, you can propagate the events to the parent window. It's pretty nasty, but will get it working 😬 Here is an example based on your sample // boxEl exists in an IFrame
this.boxEl.addEventListener('keydown', (e) => {
const event = new Event(e.type, e); // proxy event
event.preventDefault(); // try not to do anything unexpected
window.dispatchEvent(event); // dispatch in main window
}); |
Hi @TremayneChrist thanks for the great package 🎉, Example above uses a ReactPortal to render the data, where in this case the Here is the same example with two different checks with different versions |
Hey @JayaKrishnaNamburu yep there is a bug here. So many ways to create and take ownership of elements :) |
Yes agreed, I will try to take a look if i can fix this check for both the use-cases and general use-case in common 😄 |
Great! I'm not sure if you've looked at the code yet but it's probably best to just test if |
Just seen your PR :) |
Yes yes, do you think the PR is a valid fix ? or can i close it :) |
Hi @JayaKrishnaNamburu your problem on the demo above easy to fix by use iframe document to create element instead of top windown document. The demo for the fix: https://codesandbox.io/s/observer-330-forked-39xy9?file=/src/App.tsx |
Yes, and this behaviour is only in chrome alone 😄 |
Describe the bug
If we try observe an element inside iframe it will throw an error:
It because when you check
target instanceof Element
it returnfalse
. The reason are explained here: https://stackoverflow.com/questions/52222237/instanceof-fails-in-iframeWe can try other way to check target is an element like: https://stackoverflow.com/questions/384286/how-do-you-check-if-a-javascript-object-is-a-dom-object
Or use lodash.iselement: https://www.npmjs.com/package/lodash.iselement
To Reproduce
Please try this demo on Chrome: https://codesandbox.io/s/pensive-cache-31co0
Expected behavior
It work with element inside iframe.
Frameworks/Libraries used
React
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: