Embedding Discourse Comments via Javascript


(Jeff Atwood) #177

This is correct, the design assumes it is a blog and the first post is a duplicate (excerpt, technically) of the blog body. See my blog at https://blog.codinghorror.com for an example.

(Leandro) #181

How are the topics and blogs/urls linked?
Does discourse store the discourseEmbedUrl somewhere and uses only that value (literal) to fetch the topic?

(Robin Ward) #182

The embedUrl is passed to discourse, which then enqueues a job that will crawl and import the content of the page into a topic. Comments from that topic are then displayed via an iframe on the source page.

(Leandro) #183

Is it possible to embed a topic in a protected url?
To achieve this I’ve created those topics using a public atom feed (so discourse does not need to crawl and import the content). However; when I open any url it hangs on “Loading discussion…”. I was hoping that discourse would recognise the url and load the topic anyway (without crawling).
I know this is not the expected use case, but I was wondering if it possible.


We have embedding working well, with one minor issue… Our forum is hosted in a subdirectory (sitename.com/forums). When viewing the embedded topic on the main site, the avatar images are not showing up (the urls do not include the /forums/ in the path). Oddly enough, all of the other urls in the embed are correct (the user details link, etc.)

When viewing the topic on the actual forum, the urls for the images DO correctly include the subdirectory.

I’m not seeing anything in the embed settings that would help. Any ideas?


(Robin Ward) #186

I couldn’t reproduce this. When I try locally with a relative_root set up for discourse, the embedded comments have the correct avatars, and I confirmed they have the correct path.

I reviewed the code path too and don’t see how the subdirectory could be missing - maybe it’s a plugin or something?


Thanks for taking a look. I’ll dig in a bit more and see what I can find.

(Christoph) #188

I just tried inserting the following javascript code into one of my wordpress pages by using the Code Snippets plugin:

<script type="text/javascript">
DiscourseEmbed = { discourseUrl: 'https://forum.mydomain.net/',
                               topicId: 33 };
 (function() {
   var d = document.createElement('script'); d.type = 'text/javascript'; d.async = true;
   d.src = DiscourseEmbed.discourseUrl + 'javascripts/embed.js';
   (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);

and it went horribly wrong. It brought down my entire Wordpress site. I’m not kidding. Every single URL just produced a 404 error as soon as I had saved and activated the above code in the Code Snippets plugin. I hadn’t even placed it on any page yet.

So I guess you shouldn’t do that…

If the same happened to anyone else, here’s how I got WP going again: the trick is that the Code Snippets plugin has a safe-mode switch that you can add to any URL and it will deactivate all codesnippets while calling that page: it’s simply ?snippets-safe-mode=true That way I was able to navigate to the snippet and deactivate it in safe mode.

How to enable Discourse comments via JavaScript in Wordpress?
(Philip Finlay Bryan) #195

My embedding does not work am I doing something stupid Here’s the code I am trying to embed :slight_smile:

Use the following HTML code into your site to create and embed discourse topics. Replace REPLACE_ME with the canonical URL of the page you are embedding it on.

But it just doesn’t work HELP!

(Philip Finlay Bryan) #196

ok i fixed it there was a fault in the html it put in a paragraph tag so removed it and it now works. However I can’t get it to work on a wordpress.com site it just removes the java script when I paste it in

(Erlend Sogge Heggen) #197

On a WP site you should just use the official WordPress plugin instead:

(Jerry) #198

I get an error below after add javascript into middleman.
Has anyone solved this error?

ActionView::Template::Error (undefined method custom_stylesheet' for #<Class:0x007f45571dc718>) /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/dynamic_matchers.rb:26:inmethod_missing’

(John Brandenburg) #199

Using this method, along with the Drupal module available here: https://www.drupal.org/project/discourse, whose embedding tool seems broken. I was only able to get a page with "redirected you too many times."

It seems to redirect back and forth between the test page I have the embed code on and my trydiscourse.com/session/sso URL. Any suggestions?

(Quintin Par) #203

Do you still have discourse commenting system turned one? Couldn’t find

(Jerry) #204

Oh, i updated my discourse just now.
The error changed to:

Job exception: execution expired


/usr/local/lib/ruby/2.3.0/net/http.rb:880:in `initialize'
/usr/local/lib/ruby/2.3.0/net/http.rb:880:in `open'
/usr/local/lib/ruby/2.3.0/net/http.rb:880:in `block in connect'
/usr/local/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
/usr/local/lib/ruby/2.3.0/net/http.rb:878:in `connect'
/usr/local/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
/usr/local/lib/ruby/2.3.0/net/http.rb:852:in `start'
/usr/local/lib/ruby/2.3.0/open-uri.rb:319:in `open_http'
/usr/local/lib/ruby/2.3.0/open-uri.rb:737:in `buffer_open'
/usr/local/lib/ruby/2.3.0/open-uri.rb:212:in `block in open_loop'
/usr/local/lib/ruby/2.3.0/open-uri.rb:210:in `catch'
/usr/local/lib/ruby/2.3.0/open-uri.rb:210:in `open_loop'
/usr/local/lib/ruby/2.3.0/open-uri.rb:151:in `open_uri'
/var/www/discourse/lib/freedom_patches/open_uri_redirections.rb:70:in `open_uri'
/usr/local/lib/ruby/2.3.0/open-uri.rb:717:in `open'
/usr/local/lib/ruby/2.3.0/open-uri.rb:35:in `open'
/var/www/discourse/app/models/topic_embed.rb:92:in `find_remote'
/var/www/discourse/app/models/topic_embed.rb:146:in `import_remote'
/var/www/discourse/lib/topic_retriever.rb:57:in `fetch_http'
/var/www/discourse/lib/topic_retriever.rb:44:in `perform_retrieve'
/var/www/discourse/lib/topic_retriever.rb:10:in `retrieve'
/var/www/discourse/app/jobs/regular/retrieve_topic.rb:16:in `execute'
/var/www/discourse/app/jobs/base.rb:154:in `block (2 levels) in perform'

front website error

VM3148 comments?embed_url=http%3A%2F%2F10.128.8.152%3A4567%2Fquick-start%2F:17 Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://club.oneapm.com') does not match the recipient window's origin ('').
postUp	@	VM3148 comments?embed_url=http%3A%2F%2F10.128.8.152%3A4567%2Fquick-start%2F:17
window.onload	@	VM3148 comments?embed_url=http%3A%2F%2F10.128.8.152%3A4567%2Fquick-start%2F:38

Embed Discourse comments with on-page commenting?
(Robin Ward) #205

execution expired means that there is timeout while trying to reach your site from the discourse install. You should make sure that there’s nothing preventing your discourse forum from reaching your website where you’ve embedded it.

(Ben Porter) #206

Nah, I removed them. It all worked well though!

Embed Discourse comments with on-page commenting?
(Jerry) #207

Thank you very much. It is now running.

(Raphaël Jadot) #208


I tried as much things as I could, but the comments are not displayed and I have these javascript errors:

La ressource à l’adresse « https://discourse-static.openmandriva.org/mini-profiler-resources/includes.js?v=52dc741c63ccbaf9d87102ee24033482 » a été bloquée en raison d’un type MIME incorrect (X-Content-Type-Options: nosniff).

Meaning that the include.js files with query are blocked because of an incorrect mime type, following the «X-Content-Type-Options: nosniff» rule.

How can I prevent these files to be blocked?

(Robin Ward) #209

Mini profiler should not be the real error here. In fact you can disable it by visiting your main site by adding ?pp=disable to the URL.

Is there another error in the log not related to mini profiler?

Embed Discourse comments with on-page commenting?