admin管理员组

文章数量:1644024

这篇文章只是个人学习笔记,所以结构不清,信息不全,建议阅读原版项目手册。

 

JSDOM 是用nodejs实现的用于测试的虚拟浏览器。

基本例子

const dom = new JSDOM(``, {
  url: "https://example/",
  referrer: "https://example/",
  contentType: "text/html",
  includeNodeLocations: true,
  storageQuota: 10000000
});
  • url 默认为 "about:blank".默认是规范化的,所以写了https:example会自动变成https://example/
  • referrer just affects the value read from document.referrer. It defaults to no referrer (which reflects as the empty string).
  • contentType 默认为 "text/html".
  • includeNodeLocations 保存页面位置,为了性能,默认为 false 
  • storageQuota localStorage 和 sessionStorage 的最大存储大小。默认为 5,000,000.

重要参数

runScripts

runScripts 设置为  "dangerously" 才能在页面上执行js

pretendToBeVisual

当pretendToBeVisual设置为true时,会发生以下事情:

  • 让 document.hidden 返回 false 而不是 true
  • 让 document.visibilityState 返回 "visible" 而不是"prerender"
  • 启用之前不存在的 window.requestAnimationFrame() 和 window.cancelAnimationFrame() 方法

本文标签: 学习笔记浏览器jsdom