Giter Club home page Giter Club logo

jsdom-browser's Introduction

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.

jsdom-browser's People

Contributors

sttk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.