@kotori-bot/browser
Version:
browser service supports for kotori-bot
66 lines (65 loc) • 2.48 kB
JavaScript
/**
* @Package @kotori-bot/browser
* @Version 1.0.0
* @Author Hotaru <me@hotaru.icu>
* @Copyright 2024-2025 Hotaru. All rights reserved.
* @License BAN-ZHINESE-USING
* @Link https://github.com/kotorijs/kotori
* @Date 16:13:46
*/
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var src_exports = {};
__export(src_exports, {
default: () => Browser
});
module.exports = __toCommonJS(src_exports);
var import_kotori_bot = require("kotori-bot");
var import_puppeteer = __toESM(require("puppeteer"));
class Browser extends import_kotori_bot.Service {
instance;
constructor(ctx) {
super(ctx, {}, "browser");
}
async start() {
this.ctx.logger.debug("Starting browser service");
if (this.instance) throw new import_kotori_bot.KotoriError("Browser instance is already running");
this.instance = await import_puppeteer.default.launch({
headless: true
});
}
async stop() {
if (this.instance) this.instance.close();
this.instance = void 0;
}
page() {
if (!this.instance) throw new import_kotori_bot.KotoriError("Browser instance is not running");
return this.instance.newPage();
}
}