Problem/Motivation
When using Twitter Media with "Twitter embed" display following javascript error appears:
Uncaught TypeError: Illegal invocation
at r (http://platform.twitter.com/widgets.js:9:20028)
Looks that problem is in integration of twitter, because error is triggered by following code in file (.../media_entity_twitter/js/twitter.js):
twttr.widgets.load(context);
context is actually document and that is what fails. If load() method is executed without parameters, it works properly. Also it works properly, if context is some sub element in document root (fe. document.body).
Proposed resolution
Possible solution is to execute load always for full page body -> so execute load() without parameters. In this case context can't be wrong, but whole page is scanned for widgets.
Twitter Docs: Initializing embedded twitter content
Comments
Comment #2
mtodor commentedHere is patch with proposed solution.
Comment #3
badrange commentedI added this patch to a project, the javascript errors disappeared and the tweets still appear as expected. Thanks mtodor!
Comment #4
tjwelde commentedCan there be a performance issue? Twitter included the context parameter for a reason, or not?
Comment #5
slashrsm commentedGood point @tjwelde. I am not saying that the patch isn't OK, but we should investigate this a bit deeper to make sure we're not introducing any new regressions. Test coverage would also be nice.
Comment #6
mtodor commentedHere is other possible solution. Basically checking if context is element and use it, in other hand - run init on document.body.
Comment #7
mtodor commentedComment #8
othermachines commentedPatch in #6 got rid of the error for me. Thanks!
Comment #9
esteinborn commentedConfirmed Patch #6 fixed the error on my end.
Comment #10
esteinborn commentedComment #11
justin2pin commentedPatch #6 threw an error for me – "_ is undefined". Refactored slightly to remove dependency on Underscore.
Comment #12
volkerk commentedAligned check to be similar to underscore: https://underscorejs.org/docs/underscore.html#section-146
Comment #13
volkerk commentedComment #15
chr.fritschRe-uploading #12 after tests were fixed
Comment #18
chr.fritschCommitted to both branches.