Twitter.widgets.createWidget, parameters and targetEl being reversed


We have been using the createWidget function to load widgets on our website and suddenly we began receiving an error that r.appendChild was not a function.

Digging down into it it appears that the parameters and target element are being reversed. It works sometimes and it does not work other times, it appears that it may be an issue with a particular tweet.

Here is the gist of the function:

function $loadTweet( e){  //e is the target dom element
  var tweetToLoad = ...;
  var cbFunction = this.onTweetLoaded;
  var loadedFunction = function(el){
    if (el && el.contentDocument) {
      var postElement = el.contentDocument.querySelector('.Tweet-text');, postElement);
  var config = {cards:'hidden', converstation:'none', dnt:'true'};
  var twObj = (new $wnd.twttr.widgets.createTweet(tweetToLoad, e, config)).then(loadedFunction);
  return twObj;

Here is a tweet that it appears to be not working on 677922279905468416.
Here is a tweet that it appears to be working on 689621760044564480.

In the case where it is working:

parameters looks like:

    cards: "hidden"
    converstation: "none"
    dnt: "true"
    hideCard: true
    hideThread: false
    tweetId: "689621760044564480"

targetEl: div#tweet-689621760044564480

in the case where it is not working:

parameters: Object 
tweetId: "677922279905468416"

targetEl: Object

    cards: "hidden"
    converstation: "none"
    dnt: "true"
    hideCard: true
    hideThread: false

What could cause the dom object to be dropped and the config be shoved into the targetEl parameter?


We are running into the same problem but in our case none of our tweet IDs appear to be working.


Same problem !


I have figured it out. A third party library we have recently introduced is replacing the window.Node predefined object with a function that no longer has the Node.ELEMENT_NODE property so it is causing the node check to fail and to swap the config properties for the element because Node.ELEMENT_NODE is now undefined and config.nodeType is also undefined so the check:

return t ? t.nodeType === Node.ELEMENT_NODE 

is true when the twitter api is parsing out the arguments from the createWidget function.

Javascript is great.



Thanks so much for debugging that. Bugs this like are… the worst. Can you tell me which library you’re using that provides the broken implementation of Node? We can investigate different techniques to get a reference to the underlying enum.

Best short term fix, I guess, would be add some code to your page after the broken library loads is to just define Node.ELEMENT_NODE = 1 and everything should work again.




benward, thanks for replying. It is actually a library from another internal project. I have spoken to the developer and he is in the process of correcting his mistake and properly namespacing his library.