docsforadobe / aequery

MIT License
41 stars 8 forks source link

aeq.extend throwing `reflect is read only` error, sometimes #58

Open zlovatt opened 3 years ago

zlovatt commented 3 years ago

Description: Certain scripts change the DOM in some way such that aeq.extend throws reflect is read only error.

Steps to reproduce:

Workaround:


The error is on this line specifically: https://github.com/aenhancers/aequery/blob/66f66cfb2a4788175c77797e7a6680da15c2a462/lib/main.js#L173

I'm unsure what these other scripts are changing in the DOM to cause this error; not sure how best to diagnose, either.

Can add a try/catch around this line, but that feels like not the best solution here.

rafikhan commented 1 year ago

A try/catch isn't ideal but you can be selective about it. You can do that for just the reflect error and re-throw if it's something else. That way you aren't swallowing everything. Something similar to this...

try {
   target[name] = copy;
}
catch(e) {
   var isReflectErrorCausedByOtherScriptsMutatingTheDom = (e.message === 'reflect is read only');

   if (!isReflectErrorCausedByOtherScriptsMutatingTheDom) {
      // See https://github.com/aenhancers/aequery/issues/58 for context on why this is here.
      throw e;
   }
}