Socket
Socket
Sign inDemoInstall

@secret-agent/puppet

Package Overview
Dependencies
17
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.5.14 to 1.5.15

lib/BrowserProcess.d.ts

9

index.d.ts

@@ -9,18 +9,19 @@ import { IBoundLog } from '@secret-agent/interfaces/ILog';

import IDevtoolsSession from '@secret-agent/interfaces/IDevtoolsSession';
import Resolvable from '@secret-agent/commons/Resolvable';
export default class Puppet extends TypedEventEmitter<{
close: void;
}> {
get browserId(): string;
readonly id: number;
readonly browserEngine: IBrowserEngine;
supportsBrowserContextProxy: boolean;
isReady: Resolvable<void | Error>;
isStarted: boolean;
private readonly launcher;
private isShuttingDown;
private isStarted;
private browser;
constructor(browserEngine: IBrowserEngine, args?: IPuppetLaunchArgs);
start(attachToDevtools?: (session: IDevtoolsSession) => Promise<any>): Promise<Puppet>;
isSameEngine(other: Puppet): boolean;
newContext(plugins: ICorePlugins, logger: IBoundLog, proxy?: IProxyConnectionOptions): Promise<IPuppetContext>;
close(): Promise<void>;
private browserDidClose;
close(): Promise<void | Error>;
}

@@ -6,4 +6,5 @@ "use strict";

const eventUtils_1 = require("@secret-agent/commons/eventUtils");
const launchProcess_1 = require("./lib/launchProcess");
const Resolvable_1 = require("@secret-agent/commons/Resolvable");
const PuppetLaunchError_1 = require("./lib/PuppetLaunchError");
const BrowserProcess_1 = require("./lib/BrowserProcess");
const { log } = Logger_1.default(module);

@@ -14,3 +15,3 @@ let puppBrowserCounter = 1;

super();
this.isShuttingDown = false;
this.isReady = new Resolvable_1.default();
this.isStarted = false;

@@ -30,3 +31,16 @@ this.browserEngine = browserEngine;

}
get browserId() {
var _a;
return (_a = this.browser) === null || _a === void 0 ? void 0 : _a.id;
}
async start(attachToDevtools) {
const parentLogId = log.info('Puppet.Starting', {
sessionId: null,
name: this.browserEngine.name,
fullVersion: this.browserEngine.fullVersion,
});
if (this.isStarted) {
await this.isReady.promise;
return this;
}
try {

@@ -37,6 +51,15 @@ this.isStarted = true;

}
const launchedProcess = await launchProcess_1.default(this.browserEngine.executablePath, this.browserEngine.launchArguments, this.browserDidClose.bind(this));
const launchedProcess = new BrowserProcess_1.default(this.browserEngine);
const hasError = await launchedProcess.hasLaunchError;
if (hasError)
throw hasError;
launchedProcess.once('close', () => this.emit('close'));
this.browser = await this.launcher.createPuppet(launchedProcess, this.browserEngine);
this.browser.onDevtoolsAttached = attachToDevtools;
this.browser.onDevtoolsPanelAttached = attachToDevtools;
this.supportsBrowserContextProxy = this.browser.majorVersion >= 85;
this.isReady.resolve();
log.stats('Puppet.Started', {
sessionId: null,
parentLogId,
});
return this;

@@ -46,12 +69,15 @@ }

const launchError = this.launcher.translateLaunchError(err);
throw new PuppetLaunchError_1.default(launchError.message, launchError.stack, launchError.isSandboxError);
const puppetLaunchError = new PuppetLaunchError_1.default(launchError.message, launchError.stack, launchError.isSandboxError);
this.isReady.reject(puppetLaunchError);
log.stats('Puppet.LaunchError', {
puppetLaunchError,
sessionId: null,
parentLogId,
});
await this.isReady.promise;
}
}
isSameEngine(other) {
return (this.browserEngine.executablePath === other.browserEngine.executablePath &&
this.browserEngine.launchArguments.toString() ===
other.browserEngine.launchArguments.toString());
}
newContext(plugins, logger, proxy) {
if (!this.isStarted || !this.browser) {
async newContext(plugins, logger, proxy) {
await this.isReady.promise;
if (!this.browser) {
throw new Error('This Puppet instance has not had start() called on it');

@@ -65,22 +91,29 @@ }

var _a;
if (this.isShuttingDown || !this.isStarted)
if (!this.isStarted)
return;
this.isShuttingDown = true;
log.stats('Puppet.Closing');
if (this.isShuttingDown)
return this.isShuttingDown;
const parentLogId = log.stats('Puppet.Closing');
try {
await ((_a = this.browser) === null || _a === void 0 ? void 0 : _a.close());
// if we started to get ready, clear out now
this.isStarted = false;
if (this.isReady) {
const err = await this.isReady.catch(startError => startError);
this.isReady = null;
if (err)
return;
}
this.isShuttingDown = (_a = this.browser) === null || _a === void 0 ? void 0 : _a.close();
await this.isShuttingDown;
}
catch (error) {
log.error('Puppet.Closing:Error', { sessionId: null, error });
log.error('Puppet.Closing:Error', { parentLogId, sessionId: null, error });
}
finally {
this.emit('close');
log.stats('Puppet.Closed');
log.stats('Puppet.Closed', { parentLogId, sessionId: null });
}
}
browserDidClose() {
this.emit('close');
}
}
exports.default = Puppet;
//# sourceMappingURL=index.js.map
/// <reference types="node" />
import IRegisteredEventListener from '@secret-agent/interfaces/IRegisteredEventListener';
export declare class PipeTransport {
import { ChildProcess } from 'child_process';
import IConnectionTransport from '@secret-agent/interfaces/IConnectionTransport';
export declare class PipeTransport implements IConnectionTransport {
pipeWrite: NodeJS.WritableStream;
pendingMessage: string;
eventListeners: IRegisteredEventListener[];
onMessageFn?: (message: string) => void;
isClosed: boolean;
onMessageFn: (message: string) => void;
readonly onCloseFns: (() => void)[];
private isClosing;
constructor(pipeWrite: NodeJS.WritableStream, pipeRead: NodeJS.ReadableStream);
end(message: string): void;
send(message: string): void;
constructor(childProcess: ChildProcess);
send(message: string): boolean;
close(): void;
private emit;
private onReadClosed;
private dispatch;
private onData;
}

@@ -24,8 +24,9 @@ "use strict";

class PipeTransport {
constructor(pipeWrite, pipeRead) {
constructor(childProcess) {
this.isClosed = false;
this.onCloseFns = [];
this.isClosing = false;
const { 3: pipeWrite, 4: pipeRead } = childProcess.stdio;
this.pipeWrite = pipeWrite;
this.pipeWrite.on('error', error => {
if (this.isClosing)
if (this.isClosed)
return;

@@ -36,3 +37,3 @@ log.error('PipeTransport.WriteError', { error, sessionId: null });

this.eventListeners = eventUtils_1.addEventListeners(pipeRead, [
['data', this.dispatch.bind(this)],
['data', this.onData.bind(this)],
['close', this.onReadClosed.bind(this)],

@@ -43,12 +44,13 @@ ['error', error => log.error('PipeTransport.ReadError', { error, sessionId: null })],

}
end(message) {
this.isClosing = true;
this.send(message);
this.close();
}
send(message) {
this.pipeWrite.write(`${message}\0`);
if (!this.isClosed) {
this.pipeWrite.write(`${message}\0`);
return true;
}
return false;
}
close() {
this.pipeWrite = null;
if (this.isClosed)
return;
this.isClosed = true;
EventUtils.removeEventListeners(this.eventListeners);

@@ -66,3 +68,3 @@ }

}
dispatch(buffer) {
onData(buffer) {
let end = buffer.indexOf('\0');

@@ -69,0 +71,0 @@ if (end === -1) {

{
"name": "@secret-agent/puppet",
"version": "1.5.14",
"version": "1.5.15",
"description": "Puppet driver",

@@ -25,8 +25,8 @@ "main": "index.js",

"dependencies": {
"@secret-agent/commons": "1.5.14",
"@secret-agent/interfaces": "1.5.14",
"@secret-agent/puppet-chrome": "1.5.14",
"ws": "^7.4.4"
"@secret-agent/commons": "1.5.15",
"@secret-agent/interfaces": "1.5.15",
"@secret-agent/puppet-chrome": "1.5.15",
"ws": "^7.4.6"
},
"gitHead": "9f0371cf96ced42fcbba9cb422402e81c58c3705"
"gitHead": "67bc0b6f0f62b8675992dd3e1ede79a21f25b32f"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc