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.
$ npm install jsdom-browser --save-dev
const Browser = require('jsdom-browser')
const browser = new Browser()
const window0 = browser.newWindow()
window0.name = 'win0'
const windowConfig0 = browser.getConfig(window0)
windowConfig0.top = 200
windowConfig0.left = 300
window0.screenX // => 300
window0.screenY // => 200
window0 === browser.getWindow(0) // by index
window0 === browser.getWidnow('win0') // by name
window0 === browser.getWindow(windowConfig0) // by window config
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.
})
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.
})
- 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 ...
Copyright (C) 2017 Takayuki Sato
This program is free software under MIT License. See the file LICENSE in this distribution for more details.