Google docs onebox gem requires a "published" document

AI-generated summary

Users report issues with Google Docs oneboxing in Discourse, primarily due to Google’s requirement that documents be published (not just shared) for embedding. downey first identified the problem, noting blank placeholders and X-Frame-Options errors. techAPJ clarified that publishing is mandatory and confirmed embedding works for published docs. riking asked if URLs could be auto-converted to publish format, but techAPJ explained only owners can publish, and appending /pub doesn’t suffice.

Users like alehandrof and Andrew_Shanahan expressed frustration over broken functionality, especially for shared-but-unpublished docs, and requested disabling oneboxes or adding domain blacklists. Workarounds include adding a space before the URL or avoiding standalone lines. codinghorror and sam agreed embedding full docs is excessive and suggested opt-in or generic link previews instead.

techAPJ implemented improved previews with bold type labels (e.g., “Google Docs”) for private docs and made icons clickable. mcwumbly and erlend_sh suggested adding status notes like “Document is private,” which was implemented [22]. alehandrof reported URL path inconsistencies, later fixed [25].

Concerns were raised about overly long, redundant summaries for public docs [26], with sam proposing metadata like edit dates instead — though techAPJ noted this requires Google API access. Some users, like ewanly, still saw “Private” errors on published sheets, suggesting edge cases remain.

Community members like Andrew_Shanahan lamented lost functionality (e.g., weight-tracking spreadsheets), with Falco suggesting custom plugins as a workaround. Others, like burke and Hugh_Roberts, miss embedded docs and slides, urging reconsideration of opt-in embedding.

Embedding a Google document via the onebox gem seems to be broken. All that displays is a blank placeholder. When trying new posts, I get the following error in the console:

Load denied by X-Frame-Options: (Google Doc URL) does not permit cross-origin framing.

I’ll paste the URL of a sample document, https://docs.google.com/document/d/1IQGdx-1X-E_W3O5PSiV9RF1hhjI5hryWZF9FFYNv4Oc/edit?usp=sharing, in a line by itself here:

https://docs.google.com/document/d/1IQGdx-1X-E_W3O5PSiV9RF1hhjI5hryWZF9FFYNv4Oc/edit?usp=sharing

Added on my list. :pencil:

Michael, are you sure you published the Google Doc you are trying to onebox?

Google Doc needs to be published (not shared) for embedding. More info here.

In my testing the published Google Doc is getting embedded.


Can we convert the URLs into the publish form automatically?

May want to build on top of FEATURE: Add placeholder for google docs oneboxes by riking · Pull Request #307 · discourse/onebox · GitHub so we don’t get iframe flashing.

I don’t think so. I believe only the document owner has the rights to publish that document.

Simply appending /pub at the end of the URL will not allow embedding of that document.

:+1: That worked. Thanks for the insight!

That said, I don’t know that people would automatically think to do this. Is there any way to get around the limitation so that a “share” works? Alternatively, is it possible to display some type of useful error message rather than just empty space?

Good point. I’ll see what I can do, added on my list.

Best solution would IMHO be to just disable the onebox for docs that were only shared and not published, not sure how to detect this. But I noticed that for documents I share all URL paths end with /edit, e.g. https://docs.google.com/document/d/1kq3ci5beAUwlmWZUKuuVYCPIxcFEuPwKJk8M9XMvGT8/edit?usp=sharing, while the published URL ends with /pub, e.g. https://docs.google.com/document/d/1kq3ci5beAUwlmWZUKuuVYCPIxcFEuPwKJk8M9XMvGT8/pub

Another issue with the Google Docs Onebox is that they do not provide any link to the actual document, which often would make viewing easier instead of only relying on the embedded version.

In my community, we post a lot of Google Docs & Sheets that have been shared but not published. According to this topic, this results in a broken onebox.

Until there’s a better solution, I would like to disable oneboxes for Google Docs. Is this possible?

I’m not aware of any way to disable it.

In this case, I’d like to request a setting to blacklist domains – the inverse of this:

(I’m not entirely sure if there’s a formal way of initiating feature requests, short of becoming a paying customer. I just type here and hope for the best.)

Apologies for repeating myself, but I’m getting quite a bit of flak about this from my community. The Google Docs onebox is kind of half-baked and I would very much like to be able to turn it off.

The only workaround I’ve found is to run the link along with the previous paragraph of text. (I.e., not putting it on a line of its own.) I found this by trial and error and I’m pretty techie. It’s not really feasible to instruct users We refer to Google Docs a lot, and I’ve gotten into the habit of editing people’s posts in this manner to prevent the onebox from appearing.

In any case, I think embedding the document is overkill and should be optional. I much prefer Slack’s approach:

An attractive link is sufficient. It’s a spreadsheet, after all. I’m not going to try and view it in a tiny window.

Just put a space in front of the link. Not sure how that’s too “techie” of a workaround, for now…

Ah, the space is useful as well for me. I meant “techie” in the sense that my users (mostly academics and higher ed staff) generally don’t actively look for ways to thwart their technology. If they don’t like how something works they just put up with it and/or complain :smiley:

I agree with this @techAPJ

Can you add that to your list? Embedding a full Google spreadsheet, doc, etc is kind of insane when you think about it..

Yeah, if anything it should be optional, opt-in. I would hold off for 1.7 though and just have it use the generic default onebox support (after mini onebox is built)

Okay, this is now done.

Sheet:

https://docs.google.com/spreadsheets/d/1FdgO2IrP99W4KtE2ImtEVE-qMHNFai5MyeKxZFv04oc/edit?usp=sharing

Document:

Form:

Slide:

When the doc is not public, the title and contents can’t be pulled in by the onebox, so the click target is a lot less obvious. Here’s a screenshot of an example:

Perhaps that “title” should be rendered in bold blue text as “Google Sheets” or “Google Docs” or “Google Slides” when the title content can’t be retrieved?

Eg:

Yes, good point! I’ll make it so.

While you’re at it, would it be possible to make the large icon clickable as well?