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

mtodor created an issue. See original summary.

mtodor’s picture

Status: Active » Needs review
StatusFileSize
new461 bytes

Here is patch with proposed solution.

badrange’s picture

I added this patch to a project, the javascript errors disappeared and the tweets still appear as expected. Thanks mtodor!

tjwelde’s picture

Can there be a performance issue? Twitter included the context parameter for a reason, or not?

slashrsm’s picture

Status: Needs review » Needs work
Issue tags: +D8Media, +Needs tests

Good 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.

mtodor’s picture

StatusFileSize
new426 bytes

Here is other possible solution. Basically checking if context is element and use it, in other hand - run init on document.body.

mtodor’s picture

Status: Needs work » Needs review
othermachines’s picture

Patch in #6 got rid of the error for me. Thanks!

esteinborn’s picture

Confirmed Patch #6 fixed the error on my end.

esteinborn’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
Status: Needs review » Reviewed & tested by the community
justin2pin’s picture

StatusFileSize
new432 bytes

Patch #6 threw an error for me – "_ is undefined". Refactored slightly to remove dependency on Underscore.

volkerk’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new441 bytes

Aligned check to be similar to underscore: https://underscorejs.org/docs/underscore.html#section-146

volkerk’s picture

Version: 8.x-2.x-dev » 8.x-1.x-dev

Status: Needs review » Needs work

The last submitted patch, 12: 2829999-12.patch, failed testing. View results

chr.fritsch’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
Status: Needs work » Needs review
StatusFileSize
new441 bytes

Re-uploading #12 after tests were fixed

  • chr.fritsch committed 66fdcaa on 8.x-1.x
    Issue #2829999 by mtodor, volkerk, justin2pin, chr.fritsch: Javascript...

  • chr.fritsch committed 24c6301 on 8.x-2.x
    Issue #2829999 by mtodor, volkerk, justin2pin, chr.fritsch: Javascript...
chr.fritsch’s picture

Status: Needs review » Fixed

Committed to both branches.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.