Comparing version
@@ -22,7 +22,7 @@ "use strict"; | ||
* Constructs a new instance of the BrowsingContext. | ||
* @param {BiDi} BidiConnection - The BiDi connection object to use. | ||
* @param {BiDi} BiDiConnection - The BiDi connection object to use. | ||
*/ | ||
constructor(BidiConnection) { | ||
this._ws = BidiConnection; | ||
this._events = new events_1.default(BidiConnection); | ||
constructor(BiDiConnection) { | ||
this._ws = BiDiConnection; | ||
this._events = new events_1.default(BiDiConnection); | ||
} | ||
@@ -29,0 +29,0 @@ /** |
@@ -12,2 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const events_1 = require("./events"); | ||
/** | ||
@@ -24,4 +25,12 @@ * Network class provides methods to manage network requests and responses | ||
this._ws = BidiConnection; | ||
this._events = new events_1.NetworkEvents(BidiConnection); | ||
} | ||
/** | ||
* Gets BrowsingContext events. | ||
* @returns {NetworkEvents} The BrowsingContext events. | ||
*/ | ||
get events() { | ||
return this._events; | ||
} | ||
/** | ||
* Adds a network intercept. | ||
@@ -28,0 +37,0 @@ * @param context - The parameters for adding the network intercept. |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.NetworkEvents = void 0; | ||
const commands_1 = __importDefault(require("../session/commands")); | ||
class NetworkEvents { | ||
/** | ||
* Construct a new BrowsingContextEvents instance. | ||
* @param {BiDi} BiDiConnection The connected BiDi instance | ||
*/ | ||
constructor(BiDiConnection) { | ||
this._ws = BiDiConnection; | ||
this._connection = this._ws.getConnection; | ||
this._session = new commands_1.default(BiDiConnection); | ||
this.eventSubscriptions = new Map(); | ||
} | ||
/** | ||
* Get currently subscribed event data. | ||
* @return {Map<NetworkEventName, NetworkEventSubscriptionType>} The map of current event subscriptions. | ||
*/ | ||
get eventSubscriptionData() { | ||
return this.eventSubscriptions; | ||
} | ||
/** | ||
* Handles event subscription and message processing for a specific event. | ||
* @param {NetworkEventName} eventName - Name of the event to subscribe to. | ||
* @return {Promise<void>} | ||
* @private | ||
*/ | ||
handleEvent(eventName) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const event = { | ||
events: 'network.' + eventName, | ||
}; | ||
yield this._session.subscribe(event); | ||
this._connection.on('message', (data) => { | ||
const messageData = JSON.parse(data.toString()); | ||
if ('method' in messageData && 'params' in messageData) { | ||
if (messageData.method === 'network.' + eventName) { | ||
this.eventSubscriptions.set(eventName, messageData); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* Handles auth required event | ||
* @return {Promise<void>} | ||
*/ | ||
authRequired() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.handleEvent('authRequired'); | ||
}); | ||
} | ||
/** | ||
* Handles before request sent event | ||
* @return {Promise<void>} | ||
*/ | ||
beforeRequestSent() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.handleEvent('beforeRequestSent'); | ||
}); | ||
} | ||
/** | ||
* Handles fetch error event | ||
* @return {Promise<void>} | ||
*/ | ||
fetchError() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.handleEvent('fetchError'); | ||
}); | ||
} | ||
/** | ||
* Handles response completed event | ||
* @return {Promise<void>} | ||
*/ | ||
responseCompleted() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.handleEvent('responseCompleted'); | ||
}); | ||
} | ||
/** | ||
* Handles response started event | ||
* @return {Promise<void>} | ||
*/ | ||
responseStarted() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.handleEvent('responseStarted'); | ||
}); | ||
} | ||
} | ||
exports.NetworkEvents = NetworkEvents; |
@@ -17,7 +17,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
* Constructs a new instance of the BrowsingContext. | ||
* @param {BiDi} BidiConnection - The BiDi connection object to use. | ||
* @param {BiDi} BiDiConnection - The BiDi connection object to use. | ||
*/ | ||
constructor(BidiConnection) { | ||
this._ws = BidiConnection; | ||
this._events = new BrowsingContextEvents(BidiConnection); | ||
constructor(BiDiConnection) { | ||
this._ws = BiDiConnection; | ||
this._events = new BrowsingContextEvents(BiDiConnection); | ||
} | ||
@@ -24,0 +24,0 @@ /** |
@@ -10,2 +10,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { NetworkEvents } from "./events"; | ||
/** | ||
@@ -22,4 +23,12 @@ * Network class provides methods to manage network requests and responses | ||
this._ws = BidiConnection; | ||
this._events = new NetworkEvents(BidiConnection); | ||
} | ||
/** | ||
* Gets BrowsingContext events. | ||
* @returns {NetworkEvents} The BrowsingContext events. | ||
*/ | ||
get events() { | ||
return this._events; | ||
} | ||
/** | ||
* Adds a network intercept. | ||
@@ -26,0 +35,0 @@ * @param context - The parameters for adding the network intercept. |
@@ -1,1 +0,96 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
import Session from "../session/commands"; | ||
export class NetworkEvents { | ||
/** | ||
* Construct a new BrowsingContextEvents instance. | ||
* @param {BiDi} BiDiConnection The connected BiDi instance | ||
*/ | ||
constructor(BiDiConnection) { | ||
this._ws = BiDiConnection; | ||
this._connection = this._ws.getConnection; | ||
this._session = new Session(BiDiConnection); | ||
this.eventSubscriptions = new Map(); | ||
} | ||
/** | ||
* Get currently subscribed event data. | ||
* @return {Map<NetworkEventName, NetworkEventSubscriptionType>} The map of current event subscriptions. | ||
*/ | ||
get eventSubscriptionData() { | ||
return this.eventSubscriptions; | ||
} | ||
/** | ||
* Handles event subscription and message processing for a specific event. | ||
* @param {NetworkEventName} eventName - Name of the event to subscribe to. | ||
* @return {Promise<void>} | ||
* @private | ||
*/ | ||
handleEvent(eventName) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const event = { | ||
events: 'network.' + eventName, | ||
}; | ||
yield this._session.subscribe(event); | ||
this._connection.on('message', (data) => { | ||
const messageData = JSON.parse(data.toString()); | ||
if ('method' in messageData && 'params' in messageData) { | ||
if (messageData.method === 'network.' + eventName) { | ||
this.eventSubscriptions.set(eventName, messageData); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* Handles auth required event | ||
* @return {Promise<void>} | ||
*/ | ||
authRequired() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.handleEvent('authRequired'); | ||
}); | ||
} | ||
/** | ||
* Handles before request sent event | ||
* @return {Promise<void>} | ||
*/ | ||
beforeRequestSent() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.handleEvent('beforeRequestSent'); | ||
}); | ||
} | ||
/** | ||
* Handles fetch error event | ||
* @return {Promise<void>} | ||
*/ | ||
fetchError() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.handleEvent('fetchError'); | ||
}); | ||
} | ||
/** | ||
* Handles response completed event | ||
* @return {Promise<void>} | ||
*/ | ||
responseCompleted() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.handleEvent('responseCompleted'); | ||
}); | ||
} | ||
/** | ||
* Handles response started event | ||
* @return {Promise<void>} | ||
*/ | ||
responseStarted() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.handleEvent('responseStarted'); | ||
}); | ||
} | ||
} |
@@ -12,5 +12,5 @@ import { BiDi } from "../../index"; | ||
* Constructs a new instance of the BrowsingContext. | ||
* @param {BiDi} BidiConnection - The BiDi connection object to use. | ||
* @param {BiDi} BiDiConnection - The BiDi connection object to use. | ||
*/ | ||
constructor(BidiConnection: BiDi); | ||
constructor(BiDiConnection: BiDi); | ||
/** | ||
@@ -17,0 +17,0 @@ * Gets BrowsingContext events. |
import { BiDi } from "../../index"; | ||
import * as EventType from './types'; | ||
import { NetworkEvents } from "./events"; | ||
/** | ||
@@ -9,2 +10,3 @@ * Network class provides methods to manage network requests and responses | ||
_ws: BiDi; | ||
_events: NetworkEvents; | ||
/** | ||
@@ -16,2 +18,7 @@ * Constructs a new Network instance. | ||
/** | ||
* Gets BrowsingContext events. | ||
* @returns {NetworkEvents} The BrowsingContext events. | ||
*/ | ||
get events(): NetworkEvents; | ||
/** | ||
* Adds a network intercept. | ||
@@ -18,0 +25,0 @@ * @param context - The parameters for adding the network intercept. |
{ | ||
"name": "wd-bidi", | ||
"version": "0.0.4-alpha-14", | ||
"version": "0.0.4-alpha-15", | ||
"description": "WebDriver BiDi API for automation testing", | ||
@@ -5,0 +5,0 @@ "main": "./build/cjs/index.js", |
162679
7.16%80
3.9%3942
8.27%