highlight / rrweb

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError in "initAdoptedStyleSheetObserver"

Ozymandias9000 opened this issue · comments

Context:

const originalPropertyDescriptor = Object.getOwnPropertyDescriptor(
patchTarget?.prototype,
'adoptedStyleSheets',
);
if (
hostId === null ||
hostId === -1 ||
!patchTarget ||
!originalPropertyDescriptor
)
return () => {
//
};

In the lines

const originalPropertyDescriptor = Object.getOwnPropertyDescriptor(
    patchTarget?.prototype,
    'adoptedStyleSheets',
  );

patchTarget is sometimes null. This causes getOwnPropertyDescriptor to throw TypeError: Function.getOwnPropertyDescriptor: Cannot convert undefined or null to object.

I propose null checking before:

  const originalPropertyDescriptor = patchTarget?.prototype ? Object.getOwnPropertyDescriptor(
    patchTarget.prototype,
    'adoptedStyleSheets',
  ) : null;
  if (
    hostId === null ||
    hostId === -1 ||
    !patchTarget ||
    !originalPropertyDescriptor
  )
    return () => {
      //
    };