npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

browser-js-env

v0.1.4

Published

Calling local browser to run some js code and return the result to you. You can use nodeJs interfaces or CLI interfaces.

Downloads

44

Readme

browser-js-env

Calling local browser to run some js code and return the result to you. You can use both nodeJs interfaces or CLI interfaces.

Table of Contents

Features

  • Run js code in browser, get results, can be async.
  • Easy to run js code in different browsers.
  • Make ajax easy to test.

Installation

npm i browser-js-env --save

Install on global

npm i browser-js-env -g

Quick CLI Example

check cli options [show]

  • run sample
$ ./node_modules/.bin/jsinbrowser -h 
Usage:  jsinbrowser
    -c [js code]
    -t [test directory, default is __test_in_browser_env__]
    -k [keep window, default will close window]
    -o [open template cmd for start a browser with url]
    --clean [clean test directory after running js code]


Options:
  -h, --help  Show help                                                [boolean]

cli quick start [show]

  • run sample
$ ./node_modules/.bin/jsinbrowser --clean -c "module.exports=document.title;" 
browser-js-env:test

Quick API Example

quick run [show]

let browserJsEnv = require('browser-js-env');
browserJsEnv('module.exports = document.title', {
    clean: true
}).then((title) => {
    console.log(title);
});
  • run sample
$ node test.js 
browser-js-env:test

support promise [show]

let browserJsEnv = require('browser-js-env');

browserJsEnv(`
module.exports = new Promise((resolve) => {
    setTimeout(() => {
        resolve(12)
    }, 50);
})`,

    {
        clean: true
    }).then((value) => {
    console.log(value);
});
  • run sample
$ node test.js 
12

support commonJs (by using webpack) [show]

let browserJsEnv = require('browser-js-env');
browserJsEnv("var path = require('path');module.exports = path.join('/a', 'b/c');",

    {
        clean: true
    }).then((title) => {
    console.log(title);
});
  • run sample
$ node test.js 
/a/b/c

try using safari as a browser [show]

let browserJsEnv = require('browser-js-env');
browserJsEnv('module.exports = 2 + 8;', {
    clean: true,
    open: 'open -a /Applications/Safari.app <%=url%>' // for mac os
}).then((ret) => {
    console.log(ret);
});
  • run sample
$ node test.js 
10

try using electron as a browser [show]

const browserJsEnv = require('browser-js-env');
const electron = require('electron');
const proc = require('child_process');

browserJsEnv('module.exports = document.title', {
    // using open interface can be more flexible
    open: (url) => {
        proc.spawn(electron, [url]);
    },
    clean: true
}).then((title) => {
    console.log(title);
});
  • run sample
$ node test.js 
browser-js-env:test

try using headless chrome [show]

const browserJsEnv = require('browser-js-env');
const proc = require('child_process');

const chromeApp = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';

browserJsEnv('module.exports = 100 * 2', {
    open: (url) => {
        proc.spawn(chromeApp, ['--headless', '--disable-gpu', url]);
    },
    clean: true
}).then((title) => {
    console.log(title);
});
  • run sample
$ node test.js 
200

License

browser-js-env is MIT licensed


Document was generated by docway.