Example #1
0
// Creates an returns a new document attached to the window.
function createDocument(args) {
  var browser = args.browser;

  var features = {
    FetchExternalResources: [],
    ProcessExternalResources: [],
    MutationEvents: "2.0"
  };
  if (browser.hasFeature("scripts", true)) {
    features.FetchExternalResources.push("script");
    features.ProcessExternalResources.push("script");
  }
  if (browser.hasFeature("css", false)) {
    features.FetchExternalResources.push("css");
    features.FetchExternalResources.push("link");
  }
  if (browser.hasFeature("img", false)) features.FetchExternalResources.push("img");
  if (browser.hasFeature("iframe", true)) features.FetchExternalResources.push("iframe");

  // Based on JSDOM.jsdom but skips the document.write
  // Calling document.write twice leads to strange results
  var dom = browserAugmentation(DOM, { parsingMode: "html" });
  var document = new dom.HTMLDocument({ url: args.url, referrer: args.referrer, parsingMode: "html" });
  browserFeatures.applyDocumentFeatures(document, features);
  var window = document.parentWindow;
  Object.defineProperty(document, "window", {
    value: window,
    enumerable: true
  });
  setupWindow(window, args);

  // Give event handler chance to register listeners.
  browser.emit("loading", document);
  return document;
}
Example #2
0
// Creates an returns a new document attached to the window.
function createDocument(args) {
  const { browser } = args;

  const features = {
    FetchExternalResources:   [],
    ProcessExternalResources: [],
    MutationEvents:           '2.0'
  };
  if (args.browser.hasFeature('scripts', true)) {
    features.FetchExternalResources.push('script');
    features.ProcessExternalResources.push('script');
  }
  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');

  const window  = new Window({
    parsingMode:  'html',
    contentType:  'text/html',
    url:          args.url,
    referrer:     args.referrer
  });
  const { document } = window;
  browserFeatures.applyDocumentFeatures(document, features);
  setupWindow(window, args);

  // Give event handler chance to register listeners.
  args.browser.emit('loading', document);
  return document;
}
Example #3
0
// Creates an returns a new document attached to the window.
function createDocument(args) {
  const { browser } = args;

  const features = {
    FetchExternalResources:   [],
    ProcessExternalResources: [],
    MutationEvents:           '2.0'
  };
  if (browser.hasFeature('scripts', true)) {
    features.FetchExternalResources.push('script');
    features.ProcessExternalResources.push('script');
  }
  if (browser.hasFeature('css', false)) {
    features.FetchExternalResources.push('css');
    features.FetchExternalResources.push('link');
  }
  if (browser.hasFeature('img', false))
    features.FetchExternalResources.push('img');
  if (browser.hasFeature('iframe', true))
    features.FetchExternalResources.push('iframe');

  // Based on JSDOM.jsdom but skips the document.write
  // Calling document.write twice leads to strange results
  const dom       = browserAugmentation(DOM, { parsingMode: 'html' });
  const document  = new dom.HTMLDocument({ url: args.url, referrer: args.referrer, parsingMode: 'html' });
  browserFeatures.applyDocumentFeatures(document, features);
  const window    = document.parentWindow;
  setupDocument(document);
  setupWindow(window, args);

  // Give event handler chance to register listeners.
  browser.emit('loading', document);
  return document;
}