Uh oh!
There was an error while loading. Please reload this page.
fix: Uncaught TypeError: Illegal invocation in chrome 51 - #290
Conversation
in chrome 51, will throw error Uncaught TypeError: Illegal invocation
| SUPPORTED_METHODS.forEach(function (method) { | ||
| if (typeof overrides[method] === 'function') { | ||
| logger[method] = overrides[method]; | ||
| logger[method] = overrides[method].bind(overrides); |
There was a problem hiding this comment.
Nice, but shouldn't this be:
| logger[method]=overrides[method].bind(overrides); | |
| logger[method]=overrides[method].bind(overrides[method]); |
And by that point, maybe we can tidy up the loop a bit:
SUPPORTED_METHODS.forEach(function(method){varoverride=overrides[method];if(typeofoverride==='function'){logger[method]=override.bind(override);}});There was a problem hiding this comment.
should be this:
SUPPORTED_METHODS.forEach(function(method){varoverride=overrides[method];if(typeofoverride==='function'){logger[method]=override.bind(overrides);}});There was a problem hiding this comment.
Why bind to the object of overrides rather than the function itself? Or actually, maybe more accurate would be:
logger[method]=override.bind(logger);There was a problem hiding this comment.
You're getting that error because of this issue with Chrome. The correct thing to do is:
varlogger={};varoverride=console.log.bind(console);logger.log=override;logger.log('test');alecgibson
commented
May 10, 2019
I'm closing this, because the correct usage should be: ShareDB.logger.setMethods({log: console.log.bind(console),}); |
alecgibson
commented
May 10, 2019
Sorry, I just realised you mean this happens with the default I'm not sure that arbitrarily setting the functionLogger(){vardefaultMethods={};SUPPORTED_METHODS.forEach(function(method){// Deal with Chrome issue: https://bugs.chromium.org/p/chromium/issues/detail?id=179628defaultMethods[method]=console[method].bind(console);});this.setMethods(defaultMethods);} |
qinyang912
commented
May 10, 2019
@alecgibson Yes, I mean the default logger.. 😄 |
ericyhwang
commented
May 15, 2019
Thanks! Published in sharedb@1.0.0-beta.23 |


in chrome 51, will throw error