-
Notifications
You must be signed in to change notification settings - Fork 222
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
ResizeObserver cannot be initialized if document.body doesn't exist yet #1311
Comments
Hi @AngusMorton, thanks for the report and sorry for getting back to you late! Using the Adding debouncing might be a good idea too to keep the performance too. If you're happy to implement this change, we would really appreciate the contribution! |
Sent a potential stopgap PR until such time as this can be changed to use the resize event. |
Hey folks, would it be possible to do a patch release for the stopgap change I've contributed? We're currently blocked on it. |
Sorry for the delay @EricHeitmuller-Gusto, we'll aim to release it tomorrow! |
@matus-tomlein no apologies necessary - just needed something to tell my team 😅 |
We stream our page in and initialize Snowplow in the
<head>
, so it's possible for the tracker to start before the<body>
has been sent if the<body>
doesn't exist when Snowplow initializes it will throw an exception becausedocument.body
doesn't exist when it tries to set up theResizeObserver
.TypeError: Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element'.
Specifically, the issue is here where we assume
document.body
is defined.Possible Fix
Maybe we should use the
resize
event instead of a ResizeObserver. It has better support on old browsers and is potentially closer to what we want to know (when the windowinnerHeight
andinnerWidth
have changed), but we may need to implement some kind of debounce.Alternatively, we could just guard the initializeResizeObserver code with an
if (document.body)
.I'm happy to contribute either of those changes.
Workaround
Using
<script defer src="...">
instead of<script async src="...">
works around the issue because the script gets evaluated after the DOM is loaded.Snowplow Version
3.23.0
The text was updated successfully, but these errors were encountered: