title: Why does the docx js api work on jsfiddle (or other similar sites) but not when I load it via Tampermonkey?
body: <p>I'm currently at a beginner level in writing Javascript and have been doing a lot of self-learning over the past few months. Now, I am trying to create an automated script using Tampermonkey in order to create doc files at work. The API that I want to use to accomplish this is docx (<a href="https://docx.js.org/" rel="nofollow noreferrer">https://docx.js.org/</a>). </p>
  
  <p>My issue is the following:</p>
  
  <p>I am trying out a bit of code to test the functionality of the API, and so I just wanted to create a simple blank file, then save it to my computer to make sure that it works. So, I went to <code>jsFiddle</code> and wrote out some simple code to attach to a button to save a doc file. The code works, and a blank file is generated and is saved onto my computer.</p>
  
  <p>Now I head over to Tampermonkey and insert the same code, but when I try it out in the browser, it doesn't work, and no errors are logged. Through much digging, I <em>think</em> I was able to find the reason for why the code isn't working. One of the functions in the API, which converts the file I created into a Blob so that I can then download it as a doc file, returns a Promise. In the console, when I run the code in <code>jsfiddle</code>, I see that the status of the Promise is "resolved". When I run the code outside on any page, the status is always "pending". </p>
  
  <p>The code also successfully runs in sites similar to <code>jsfiddle</code>, such as codepen, repl, etc. I've tried many suggestions such as having the code run once the page has finished loading (using <code>window.onload</code>, <code>$(document).ready()</code>), but nothing works. I'm not sure what else <code>jsfiddle</code> does to my code that makes it execute correctly. Could it be Tampermonkey? Here is the code on <code>jsfiddle</code> for reference: <a href="http://jsfiddle.net/jcor19/qz8n4wmu/" rel="nofollow noreferrer">http://jsfiddle.net/jcor19/qz8n4wmu/</a></p>
  
  <p>And here is the Tampermonkey script code:</p>
  
  <pre><code>    // ==UserScript==
  // @name         Test Script
  // @namespace    http://tampermonkey.net/
  // @version      1.0
  // @author       me
  // @match        http://e-try.com/black.htm
  // @require      https://code.jquery.com/jquery-3.4.1.js
  // @require      https://code.jquery.com/ui/1.12.1/jquery-ui.js
  // @require      https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js
  // @require      https://unpkg.com/docx@5.0.0-rc5/build/index.js
  // ==/UserScript==
  
  jQuery(function() {
      var button = document.createElement("button");
      button.innerHTML = "Do Something";
  
      var body = document.getElementsByTagName("body")[0];
      body.appendChild(button);
  
      button.addEventListener("click", function() {
          const doc = new Document();
  
          Packer.toBlob(doc).then(blob =&gt; {
              console.log(blob);
              saveAs(blob, "example.docx");
              console.log("Document created successfully");
          });
      });
  });
  </code></pre>
  
  <p>Thank you for taking a look!</p>