Embedded Google Document Causing Intermittent Issues

I’m having trouble with an embedded Google Doc on my website. It’s showing up fine most of the time, but I keep getting this weird error:

Uncaught ReferenceError: DOCS_timing is not defined
    at pub?

I created the doc link on Google Docs. It looks something like this (with a bunch of random characters):

"https://docs.google.com/document/d/...long-string.../export?format=pdf"

Here’s the iframe I’m using in my JSX code:

<iframe
  name="DocViewer"
  src={docSource}
  onLoad={handleLoadComplete}
  style={iframeStyles}
  allow="picture-in-picture full"
>
</iframe>

The document shows up okay, but these errors pop up randomly. Any ideas what’s causing this or how to fix it?

yo, i’ve seen this b4. try clearin ur browser cache n cookies. sometimes google’s scripts get wonky. also, check if ur using the latest embed code from google. they update that stuff on the dl. if nothin works, maybe switch to a pdf viewer plugin? less hassle imo

I’ve encountered similar issues with embedded Google Docs before. The DOCS_timing error often occurs because of timing problems during the script loading process from Google. Instead of using a direct iframe and copying the URL manually, consider using the official embed code that you obtain by publishing the document to the web directly from Google Docs. This approach has resolved similar issues for me. If you continue to experience problems, you might try a fallback such as offering a static PDF version, and ensure that your website’s security settings allow resources from Google’s domains.

I’ve dealt with this exact issue in a client project. The DOCS_timing error is a pain, but there’s a workaround. Instead of using the export URL, try the published web version. Go to File > Share > Publish to web in your Google Doc, then use that embed code. It’s more stable.

Also, make sure you’re not loading the doc in an iframe that’s initially hidden. I’ve seen that cause timing issues. If you must use an iframe, consider lazy-loading it when it becomes visible.

Lastly, check your Content Security Policy headers if you have them. Sometimes they can block Google’s scripts. Adding https://docs.google.com to your script-src directive might help.

Hope this helps! Let me know if you need any clarification on these steps.