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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@d-zero/puppeteer-general-actions

v1.2.2

Published

General functions for puppeteer

Downloads

691

Readme

@d-zero/puppeteer-general-actions

Puppeteer操作のライフサイクルイベントをログするための汎用ヘルパーライブラリ。

インストール

npm install @d-zero/puppeteer-general-actions

概要

このパッケージは、Puppeteerを使った処理のフェーズごとにログを出力するためのリスナーを作成する機能を提供します。デバイスサイズや処理フェーズに応じたカラーラベル付きログ出力が可能です。

API

createListener<P>(listener: Loggers<P>): (log: (log: string) => void) => Listener<P>

フェーズごとのログ出力関数を持つリスナーを作成します。

型パラメータ:

  • P: 各フェーズのデータ型を定義するレコード型。各フェーズは{ name: string }を含む必要があります

パラメータ:

  • listener: ログ出力関数を受け取り、各フェーズのハンドラーを返す関数

戻り値:

  • ログ出力関数を受け取り、Listener<P>を返す関数

使用例:

import { createListener } from '@d-zero/puppeteer-general-actions';

// フェーズの型定義
type Phases = {
	start: { name: string; url: string };
	complete: { name: string; duration: number };
	error: { name: string; message: string };
};

// リスナーの作成
const listener = createListener<Phases>((log) => ({
	start: (data) => {
		log(`開始: ${data.url}`);
	},
	complete: (data) => {
		log(`完了 (${data.duration}ms)`);
	},
	error: (data) => {
		log(`エラー: ${data.message}`);
	},
}));

// ログ出力関数を渡してリスナーを初期化
const listen = listener(console.log);

// フェーズごとにリスナーを呼び出す
listen('start', { name: 'desktop', url: 'https://example.com' });
// 出力: " desktop " 開始: https://example.com

listen('complete', { name: 'desktop', duration: 1500 });
// 出力: " desktop " 完了 (1500ms)

listen('error', { name: 'desktop', message: 'タイムアウト' });
// 出力: " desktop " エラー: タイムアウト

型定義

Listener<P>

type Listener<P> = (phase: keyof P, data: P[keyof P]) => void;

フェーズ名とそのフェーズのデータを受け取るリスナー関数の型。

Loggers<P>

type Loggers<P> = (log: (log: string) => void) => {
	[K in keyof P]?: (data: P[K]) => void;
};

ログ出力関数を受け取り、各フェーズのハンドラーオブジェクトを返す関数の型。

機能

カラーラベル

各ログ出力には、データに含まれるnameフィールドに基づいたマゼンタ背景のラベルが自動的に付与されます。これにより、複数のデバイスサイズやプロセスを並行して処理する際に、ログの視認性が向上します。

フェーズのオプショナル性

リスナーの各フェーズハンドラーはオプショナルです。必要なフェーズのみを実装できます。

関連パッケージ

このパッケージは以下のパッケージで使用されています:

ライセンス

MIT