code: function createDocument(args) {
    const { browser } = args;
  
    const features = {
      FetchExternalResources:   [],
      ProcessExternalResources: [],
      MutationEvents:           '2.0'
    };
  
    const window  = new Window({
      parsingMode:  'html',
      contentType:  'text/html',
      url:          args.url,
      referrer:     args.referrer
    });
  
    const { document } = window;
    const documentImpl = idlUtils.implForWrapper(document)
  
    if (args.browser.hasFeature('scripts', true)) {
      features.FetchExternalResources.push('script');
      features.ProcessExternalResources.push('script');
      window._runScripts = 'dangerously';
    }
    if (args.browser.hasFeature('css', false)) {
      features.FetchExternalResources.push('css');
      features.FetchExternalResources.push('link');
    }
    if (args.browser.hasFeature('img', false))
      features.FetchExternalResources.push('img');
    if (args.browser.hasFeature('iframe', true))
      features.FetchExternalResources.push('iframe');
  
  
    browserFeatures.applyDocumentFeatures(documentImpl, features);
    setupWindow(window, args);
  
    // Give event handler chance to register listeners.
    args.browser.emit('loading', document);
    return document;
  }
docs: Creates an returns a new document attached to the window.