Twitter Native Embed

Nice work and good idea.

I worked on a little fork to use the data-theme dark mode for embed. It works fine, but I’m not an expert coder.

If you manage to add an option to use default theme or dark theme, I think it will be even better!


We’ve done all the modifications recommended above. Our issue now is only if trying to post using a mobile device… embedding a Tweet using a laptop/desktop works fine now.


Some folks want embeds and no need for “login” functionality, and so this component is going to be very popular and yes I see request for other platforms too.

Personally I like the more natural looking twitter embed style than the Onebox, if the more popular platform embeds carry over the native look it differentiates them well in the flow of a topic. Truly great work and can’t help thinking why we didn’t have this before to avoid all the complexities of the dev account setup, but there you go, needs must and the valiant and brave rise to the challenge.

¡Mucho mucho gracias!

1 Like

On another point of the fragility of embeds as content after looking at the twitter imploding topic. made me think again of an old idea I had.

If embeds were able to generate a backup bitmap of the embed preview as part of the embed function, that would guard against photobucket outcomes and similar.

I have no idea how that could be coded up but I imagine it would work in principle much like the function that grabs the image of posted image link and is stored int eh native database, while I assume that is easier since it’s an already existing file out there on a server somewhere, it would act as I suppose the same as a custom screen grab function on the fly, that occurs when an embed is committed to a discourse post.

Sites archiving a level of their content is helpful as the net ages, stuff does disappear form time to time.

I’m going to suggest another feature along these lines too here

1 Like

Thank you.

1 Like

This is important and just discovered, by putting 2 and 2 together - if you had not CSP enabled before and you use say Google Adsense, you will nuke you ads turning on CSP if using encryption (DM’s) to get the twitter component to work as there is a potential conflict!

I would like to be proven wrong with a super solution or “you did it wrong”


Presuming that oneboxing via API now requires a paid Twitter subscription, this method could/should be added to the Discourse core? Big enterprise communities can afford Elon’s fees, but it is out of reach for non-profits and small time communities.

Does this idea get support from @team?

Twitter’s erosion is a challenging case to handle. It is still the no.1 source for most news and events, used by media houses, corporations and persons of interest. Despite Elon’s shakedown, there is no credible challenger or alternative for the platform.


Unfortunately, this component is not working on my Discourse instance. We removed Twitter login keys, yet still nothing. Also enabled CSP.


Hi ljpp,

Losing rich embeds is certainly not wanted, and we’re discussing it to see what can be done properly about this. :slight_smile:

When you paste a twitter link in the composer, what does the network tab of your browser dev tools returns?
Are there errors in the javascript console?


We are thinking about it but there are two very big problems that need to be confronted here:

  1. IFRAME means we are allowing twitter to track users. There are privacy concerns.
  2. IFRAME means we need to fight the war of “unknown” height. If we have no height and only get it after we have a chat with Twitter, the page goes jumpy jumpy which can heavily impact the Discourse experience. Figuring out the height upfront is super hard.

Absolutely. This theme component workaround loads JavaScript from Twitters servers, and considering how Twitter is doing in general, this is a massive privacy risk. Therefore I am reluctant to apply this theme component, at least for now.

Tricky case indeed.


I’m really not sure what to look at, but here are the results after pasting link in the composer:

and in the preview I’m getting this message:

This is the tweet:



So embeds are working now, but composer preview still displays “Sorry, we are unable to generate…” message. When posted, everything looks good.


There was Reddit, taken by the same approach. Discussion are truly on risk (nobody listen untils it’s late like almost always).

We got Discourse, for sure :slight_smile:

1 Like

This is a feature. To prevent the iframe from being requested multiple times while editing, I didn’t allow the component to be enabled in compose.


With this installed, I notice that when going to a thread, it first takes you to ‘last post’, then the Twitter embed function populates, and it drags you back a few posts, every time.

Is there a fix for this?


We are still having an issue… nothing is embedding yet it appears everything is set up… any ideas?

1 Like

This theme component doesnt’t use the twitter api, you won’t be limited in that aspect

1 Like

Twitter’s onebox has been subject to changes as per this commit: FIX: Use Twitter API v2 for oneboxes and restore OpenGraph fallback (… · discourse/discourse@24c9053 · GitHub

I tried this theme component on my test instance, and it doesn’t show media:

Is this related?

1 Like

This theme component will only work if onebox doesn’t work

1 Like