jsdom-browser Github.io NPM MIT Licenses Build Status Build Status Coverage Status

This module simulates behaviors of a Web browser with jsdom, and will provides implementations about layouts of view elements and windows.

This module simulates Chrome on macOS for the time being, but is implemented so as to be configurable and extendable to other browsers.

Install

$ npm install jsdom-browser --save-dev

Usage

Create a browser

const Browser = require('jsdom-browser')
const browser = new Browser()

Open a blank window

const window0 = browser.newWindow()

window0.name = 'win0'

Get a window config

const windowConfig0 = browser.getConfig(window0)
windowConfig0.top = 200
windowConfig0.left = 300

window0.screenX // => 300
window0.screenY // => 200

Get a window already opened

window0 === browser.getWindow(0)  // by index
window0 === browser.getWidnow('win0') // by name
window0 === browser.getWindow(windowConfig0) // by window config

Open a window with loading a page content

browser.addContent('http://www.example.com', '<p>Hello!</p>')

const window1 = browser.openWindow('http://www.example.com')

window1.addEventListener('load', event => {
  // Called after loading content.
})

const config1 = browser.getConfig(window1)
config1.on('load', (err, win, cfg) => {
  // Called after loading content.
})

Open a child window

browser.addContent('http://sample.net', '<html> ... </html>')

const window2 = window.open('http://sample.net', '_blank', 'top=100,left=200,height=300,width=400')

window2.addEventListener('load', event => {
  // Called after loading content.
})

const config2 = browser.getConfig(window2)
config2.on('load', (err, win, cfg) => {
  // Called after loading content.
})

Progress

  • Screen
  • ScreenOrientation (Not yet)
  • Window
    • screen ✓
    • innerWidth, innerHeight, outerWidth, outerHeight, screenX, screenY, devicePixelRatio ✓
    • scrollX, scrollY, pageXOffset, pageYOffset ✓
    • moveTo, moveBy, resizeTo, resizeBy ✓
    • scroll, scrollTo, scrollBy ✓
    • open, close ✓
    • matchMedia (Not yet)
  • And planning more HTMLElements ...

References

License

Copyright (C) 2017 Takayuki Sato

This program is free software under MIT License. See the file LICENSE in this distribution for more details.