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-cookie-login

v1.0.3

Published

一个打开浏览器并登录获取cookie的小工具,一般用户命令行登录后自动化使用

Downloads

3

Readme

browser-cookie-login

中文文档

A tool that opens a browser and login to obtain cookies. Generally, it is used automatically after the user login from the command line.

Sometimes we need to use programs to call some server API, but some API require user login information. There are many ways to implement user login, among which cookie is one of them.

After we login by browser, we can obtain cookies from browser. For subsequent API access, we can directly carry the cookie in the request to know the logged-in user, and we can also call the API with corresponding permissions.

This tool is realized, the command line opens the browser to login and obtain the cookie operation.

Installation

npm install browser-cookie-login --save
# or you can use yarn
yarn add browser-cookie-login

Usages

import { getCookieValue } from "browser-cookie-login";

getCookieValue({
  cookieName: "user_session",
  url: "https://github.com/",
  resolveResult: async (browser) => {
    const url = await browser.getUrl();
    return new URL(url).host === 'github.com';
  }
}).then(resp => {
  console.log("cookie:", resp);
}).catch(error => {
  console.log(error);
});

Options

The options of getCookieValue function:

export interface IOptions {
  /**
   * The cookieName of login, such as "sessionid"
   */
  cookieName: string;
  /**
   * The login url of website, such as "https://github.com"
   */
  url: string;
  /**
   * The interval of check cookieName is existed, you need not change it, default 1 sencond.
   */
  retryInterval?: number;
  /**
   * Success page content, default "你已经登录成功,浏览器即将关闭!"
   */
  successMessage?: string;
  /**
   * Success page display duration, you need not change it, default 3 sencond. browser would close.
   */
  successShowDuration?: number;
  /**
   * see document of webdriverio.RemoteCapability
   */
  capabilities?: RemoteCapability;
  /**
   * The handler of result, when return true, the login process will exit and show success page.
   * if your login page and home page has different host, such as login page is "https://login.github.com" and home page is "https://github.com"
   * the cookie is stored on home page, you should resolve youself.
   * more please see examples
   * @param browser
   */
  resolveResult?: (browser: Browser<any>) => Promise<boolean>;
}

Development

# install dependence
npm install
# start dev
npm start
# build
npm run build

FAQ

  • If browser is close by manually, the process will not exit.