Skip to content

Cannot read properties of undefined (reading 'startTime') #41066

@qLutCh55

Description

@qLutCh55

Environment

SaaS (https://sentry.io/)

Version

NA

Steps to Reproduce

So I installed sentry.io on my application - I started getting this error "Cannot read properties of undefined (reading 'startTime')" however nowhere in my codebase do I use the word "startTime".

Examined my app.js to see that it is something coming from sentry.io code.

App.js

let n,r=0,a=[];const o=t=>{t.forEach((t=>{if(!t.hadRecentInput){const e=a[0],o=a[a.length-1];r&&t.startTime-o.startTime<1e3&&t.startTime-e.startTime<5e3?(r+=t.value,a.push(t)):(r=t.value,a=[t]),r>i.value&&(i.value=r,i.entries=a,n&&n())}}))},s=be("layout-shift",o);s&&(n=he(t,i,e.reportAllChanges),xe((()=>{o(s.takeRecords()),n(!0)})))})((t=>{const e=t.entries.pop();e&&(("undefined"==typeof __SENTRY_DEBUG__||__SENTRY_DEBUG__)&&a.kg.log("[Measurements] Adding CLS")

The related node_module file - node_modules/@sentry/tracing/esm/browser/web-vitals/getCLS.js - somewhere between line 50 and 71.

`// const handleEntries = (entries: Metric['entries']) => {
const handleEntries = (entries) => {
entries.forEach(entry => {
// Only count layout shifts without recent user input.
if (!entry.hadRecentInput) {
const firstSessionEntry = sessionEntries[0];
const lastSessionEntry = sessionEntries[sessionEntries.length - 1];

    // If the entry occurred less than 1 second after the previous entry and
    // less than 5 seconds after the first entry in the session, include the
    // entry in the current session. Otherwise, start a new session.
    if (
      sessionValue &&
      entry.startTime - lastSessionEntry.startTime < 1000 &&
      entry.startTime - firstSessionEntry.startTime < 5000
    ) {
      sessionValue += entry.value;
      sessionEntries.push(entry);
    } else {
      sessionValue = entry.value;
      sessionEntries = [entry];
    }`

Seems to call the property startTime of lastSessionEntry - which might not be available. Unfortunely I cannot provide the issue share link from sentry.io, as it contains sensitive information as user ip, etc.

Expected Result

No console or tracking error from importing sentry into application.

Actual Result

Get error - Cannot read properties of undefined (reading 'startTime')

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions