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 🙏

© 2025 – Pkg Stats / Ryan Hefner

simulate-browser

v1.2.1

Published

This library can simulate the http request actions of browser.

Readme

simulateBrowser

[simulateBrowser] (https://www.npmjs.com/package/simulate-browser) 是一個 command line 專用的假瀏覽器,能夠用來做網站測試或自動化功能,例如我可以寫一個自動登入 Facebook 網站並發送訊息給每一個朋友,或是自動登入 Yahoo 收信。

simulateBrowser 的使用方式如下。

npm install simulate-browser

下面這段程式,示範一個簡單的 command line 登入 Yahoo ,並取得 Cookie。

var b = require('simulate-browser');
var user = "[email protected]";
var pswd = "1231123";

// 連到 Yahoo Login 頁面
b.get("https://login.yahoo.com/m?.intl=tw&.done=https://tw.mobi.yahoo.com")
    .then(function (text) {
        // 處理 Form 表單資料
        var params, _crumb, reg, mat, inputs;
        params = {
            username: user,
            signin: "authtype",
            "countrycode": 886
        };

        inputs = ["_ts", "_tps", "_muh", "_crumb", "_uuid", "_seqid", "otp_channel", "otp_ref_cc_intl"];
        for (var k in inputs) {
            reg = new RegExp('<input type="hidden" name="'+inputs[k]+'" value="([^\"]+)"');
            mat = text.match(reg);
            if (mat && mat[1]) params[inputs[k]] = mat[1];

        }
        // 送出 Form 表單
        return b.post("https://login.yahoo.com/m?.intl=tw&.done=https%3A%2F%2Ftw.mobi.yahoo.com", params);
    }).fail(error)
    .then(function (text) {
        //var header = b.getResponseHeaders();
        //console.log("Firt step header = ", header , "\n\n");
        console.log(text);
        var nextUrl = "https://login.yahoo.com/account/challenge/password";
        var params, _crumb, reg, mat, inputs;
        params = {
            username: user,
            signin: "authtype",
            password: pswd,
            _ts: ts,
            verifyPassword: "登入",
            passwordContext: "yakEligible"

        };

        inputs = ["_ts", "_tps", "acrumb", "crumb", "config", "s"];
        for (var k in inputs) {
            reg = new RegExp('<input type="hidden" name="'+inputs[k]+'" value="([^\"]+)"');
            mat = text.match(reg);
            if (mat && mat[1]) params[inputs[k]] = mat[1];

        }
        console.log("Password page, Your input:", params);
        return b.post(nextUrl, params);
    }).fail(error)
    .then(function (text) {
        // 連到 My Yahoo 頁面
        return b.get("https://my.yahoo.com/");
    })
    .then(function (text) {
        // 印出  cookie
        var ret;
        ret = b.getCookieString();
        console.log("cookie = " + ret);
    });

Initialize cookie

var b = require('simulate-browser');
// object    
b.setCookies({"userId": "xxx", "PHPSESSION": "zzzz"});
// string
b.setCookies("userId=xxx; PHPSESSION=zzzz");

b.get("https://tw.mobi.yahoo.com")
    .then(function (xx) {

    });