Comparing version 0.0.4-alpha-15 to 0.0.4-alpha-16
@@ -15,3 +15,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Storage = exports.Session = exports.Network = exports.Log = exports.Input = exports.BrowsingContext = exports.Browser = exports.BiDi = void 0; | ||
exports.Storage = exports.Session = exports.Script = exports.Network = exports.Log = exports.Input = exports.BrowsingContext = exports.Browser = exports.BiDi = void 0; | ||
const ws_1 = __importDefault(require("ws")); | ||
@@ -33,2 +33,4 @@ const node_timers_1 = require("node:timers"); | ||
exports.Network = commands_7.default; | ||
const commands_8 = __importDefault(require("./modules/script/commands")); | ||
exports.Script = commands_8.default; | ||
const RESPONSE_TIMEOUT = 60 * 1000; | ||
@@ -35,0 +37,0 @@ /** |
"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()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const events_1 = require("./events"); | ||
/** | ||
* Represents a script instance that interacts with a BiDi connection. | ||
*/ | ||
class Script { | ||
/** | ||
* Constructs a new instance of the Script. | ||
* @param {BiDi} BiDiConnection - The BiDi connection object to use. | ||
*/ | ||
constructor(BiDiConnection) { | ||
this._ws = BiDiConnection; | ||
this._events = new events_1.ScriptEvents(BiDiConnection); | ||
} | ||
/** | ||
* Gets Script events. | ||
* @returns {NetworkEvents} The BrowsingContext events. | ||
*/ | ||
get events() { | ||
return this._events; | ||
} | ||
/** | ||
* Adds a preload script to the BiDi connection. | ||
* @param {AddPreloadScriptParameters} context - The parameters for adding a preload script. | ||
* @returns {Promise<AddPreloadScriptResult>} A promise that resolves with the result of adding a preload script. | ||
*/ | ||
addPreloadScript(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const params = { | ||
method: 'script.addPreloadScript', | ||
params: context | ||
}; | ||
return new Promise((resolve, reject) => { | ||
this._ws.sendCommand(params) | ||
.then(response => resolve(response)) | ||
.catch(error => reject(error)); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Disowns a script from the BiDi connection. | ||
* @param {DisownParameters} context - The parameters for disowning a script. | ||
* @returns {Promise<void>} A promise that resolves when the script is disowned. | ||
*/ | ||
disown(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const params = { | ||
method: 'script.disown', | ||
params: context | ||
}; | ||
yield this._ws.sendCommand(params); | ||
}); | ||
} | ||
/** | ||
* Calls a function on the BiDi connection. | ||
* @param {CallFunctionParameters} context - The parameters for calling a function. | ||
* @returns {Promise<EvaluateResult>} A promise that resolves with the result of calling a function. | ||
*/ | ||
callFunction(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const params = { | ||
method: 'script.callFunction', | ||
params: context | ||
}; | ||
return new Promise((resolve, reject) => { | ||
this._ws.sendCommand(params) | ||
.then(response => resolve(response)) | ||
.catch(error => reject(error)); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Evaluates a script on the BiDi connection. | ||
* @param {EvaluateParameters} context - The parameters for evaluating a script. | ||
* @returns {Promise<EvaluateResult>} A promise that resolves with the result of evaluating a script. | ||
*/ | ||
evaluate(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const params = { | ||
method: 'script.evaluate', | ||
params: context | ||
}; | ||
return new Promise((resolve, reject) => { | ||
this._ws.sendCommand(params) | ||
.then(response => resolve(response)) | ||
.catch(error => reject(error)); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Gets the realms from the BiDi connection. | ||
* @param {GetRealmsParameters} context - The parameters for getting realms. | ||
* @returns {Promise<GetRealmsResult>} A promise that resolves with the result of getting realms. | ||
*/ | ||
getRealms(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const params = { | ||
method: 'script.getRealms', | ||
params: context | ||
}; | ||
return new Promise((resolve, reject) => { | ||
this._ws.sendCommand(params) | ||
.then(response => resolve(response)) | ||
.catch(error => reject(error)); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Removes a preload script from the BiDi connection. | ||
* @param {RemovePreloadScriptParameters} context - The parameters for removing a preload script. | ||
* @returns {Promise<void>} A promise that resolves when the preload script is removed. | ||
*/ | ||
removePreloadScript(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const params = { | ||
method: 'script.removePreloadScript', | ||
params: context | ||
}; | ||
yield this._ws.sendCommand(params); | ||
}); | ||
} | ||
} | ||
exports.default = Script; |
"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.ScriptEvents = void 0; | ||
const commands_1 = __importDefault(require("../session/commands")); | ||
/** | ||
* Handles script events and subscriptions. | ||
*/ | ||
class ScriptEvents { | ||
/** | ||
* Initializes the ScriptEvents instance. | ||
* @param BiDiConnection - BiDi connection instance. | ||
*/ | ||
constructor(BiDiConnection) { | ||
this._ws = BiDiConnection; | ||
this._connection = this._ws.getConnection; | ||
this._session = new commands_1.default(BiDiConnection); | ||
this.eventSubscriptions = new Map(); | ||
} | ||
/** | ||
* Gets the event subscription data. | ||
* @returns Map of event subscriptions. | ||
*/ | ||
get eventSubscriptionData() { | ||
return this.eventSubscriptions; | ||
} | ||
/** | ||
* Handles an event subscription. | ||
* @param eventName - Name of the event. | ||
* @returns Promise that resolves when the event is handled. | ||
*/ | ||
handleEvent(eventName) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const event = { | ||
events: 'script.' + 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); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* Subscribes to message events. | ||
* @returns Promise that resolves when the subscription is successful. | ||
*/ | ||
message() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.handleEvent('message'); | ||
}); | ||
} | ||
/** | ||
* Subscribes to realm created events. | ||
* @returns Promise that resolves when the subscription is successful. | ||
*/ | ||
realmCreated() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.handleEvent('realmCreated'); | ||
}); | ||
} | ||
/** | ||
* Subscribes to realm destroyed events. | ||
* @returns Promise that resolves when the subscription is successful. | ||
*/ | ||
realmDestroyed() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.handleEvent('realmDestroyed'); | ||
}); | ||
} | ||
} | ||
exports.ScriptEvents = ScriptEvents; |
@@ -19,2 +19,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import Network from "./modules/network/commands"; | ||
import Script from "./modules/script/commands"; | ||
const RESPONSE_TIMEOUT = 60 * 1000; | ||
@@ -135,2 +136,2 @@ /** | ||
} | ||
export { BiDi, Browser, BrowsingContext, Input, Log, Network, Session, Storage }; | ||
export { BiDi, Browser, BrowsingContext, Input, Log, Network, Script, Session, Storage }; |
@@ -1,1 +0,130 @@ | ||
"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 { ScriptEvents } from "./events"; | ||
/** | ||
* Represents a script instance that interacts with a BiDi connection. | ||
*/ | ||
export default class Script { | ||
/** | ||
* Constructs a new instance of the Script. | ||
* @param {BiDi} BiDiConnection - The BiDi connection object to use. | ||
*/ | ||
constructor(BiDiConnection) { | ||
this._ws = BiDiConnection; | ||
this._events = new ScriptEvents(BiDiConnection); | ||
} | ||
/** | ||
* Gets Script events. | ||
* @returns {NetworkEvents} The BrowsingContext events. | ||
*/ | ||
get events() { | ||
return this._events; | ||
} | ||
/** | ||
* Adds a preload script to the BiDi connection. | ||
* @param {AddPreloadScriptParameters} context - The parameters for adding a preload script. | ||
* @returns {Promise<AddPreloadScriptResult>} A promise that resolves with the result of adding a preload script. | ||
*/ | ||
addPreloadScript(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const params = { | ||
method: 'script.addPreloadScript', | ||
params: context | ||
}; | ||
return new Promise((resolve, reject) => { | ||
this._ws.sendCommand(params) | ||
.then(response => resolve(response)) | ||
.catch(error => reject(error)); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Disowns a script from the BiDi connection. | ||
* @param {DisownParameters} context - The parameters for disowning a script. | ||
* @returns {Promise<void>} A promise that resolves when the script is disowned. | ||
*/ | ||
disown(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const params = { | ||
method: 'script.disown', | ||
params: context | ||
}; | ||
yield this._ws.sendCommand(params); | ||
}); | ||
} | ||
/** | ||
* Calls a function on the BiDi connection. | ||
* @param {CallFunctionParameters} context - The parameters for calling a function. | ||
* @returns {Promise<EvaluateResult>} A promise that resolves with the result of calling a function. | ||
*/ | ||
callFunction(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const params = { | ||
method: 'script.callFunction', | ||
params: context | ||
}; | ||
return new Promise((resolve, reject) => { | ||
this._ws.sendCommand(params) | ||
.then(response => resolve(response)) | ||
.catch(error => reject(error)); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Evaluates a script on the BiDi connection. | ||
* @param {EvaluateParameters} context - The parameters for evaluating a script. | ||
* @returns {Promise<EvaluateResult>} A promise that resolves with the result of evaluating a script. | ||
*/ | ||
evaluate(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const params = { | ||
method: 'script.evaluate', | ||
params: context | ||
}; | ||
return new Promise((resolve, reject) => { | ||
this._ws.sendCommand(params) | ||
.then(response => resolve(response)) | ||
.catch(error => reject(error)); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Gets the realms from the BiDi connection. | ||
* @param {GetRealmsParameters} context - The parameters for getting realms. | ||
* @returns {Promise<GetRealmsResult>} A promise that resolves with the result of getting realms. | ||
*/ | ||
getRealms(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const params = { | ||
method: 'script.getRealms', | ||
params: context | ||
}; | ||
return new Promise((resolve, reject) => { | ||
this._ws.sendCommand(params) | ||
.then(response => resolve(response)) | ||
.catch(error => reject(error)); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Removes a preload script from the BiDi connection. | ||
* @param {RemovePreloadScriptParameters} context - The parameters for removing a preload script. | ||
* @returns {Promise<void>} A promise that resolves when the preload script is removed. | ||
*/ | ||
removePreloadScript(context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const params = { | ||
method: 'script.removePreloadScript', | ||
params: context | ||
}; | ||
yield this._ws.sendCommand(params); | ||
}); | ||
} | ||
} |
@@ -1,1 +0,80 @@ | ||
"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"; | ||
/** | ||
* Handles script events and subscriptions. | ||
*/ | ||
export class ScriptEvents { | ||
/** | ||
* Initializes the ScriptEvents instance. | ||
* @param BiDiConnection - BiDi connection instance. | ||
*/ | ||
constructor(BiDiConnection) { | ||
this._ws = BiDiConnection; | ||
this._connection = this._ws.getConnection; | ||
this._session = new Session(BiDiConnection); | ||
this.eventSubscriptions = new Map(); | ||
} | ||
/** | ||
* Gets the event subscription data. | ||
* @returns Map of event subscriptions. | ||
*/ | ||
get eventSubscriptionData() { | ||
return this.eventSubscriptions; | ||
} | ||
/** | ||
* Handles an event subscription. | ||
* @param eventName - Name of the event. | ||
* @returns Promise that resolves when the event is handled. | ||
*/ | ||
handleEvent(eventName) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const event = { | ||
events: 'script.' + 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); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* Subscribes to message events. | ||
* @returns Promise that resolves when the subscription is successful. | ||
*/ | ||
message() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.handleEvent('message'); | ||
}); | ||
} | ||
/** | ||
* Subscribes to realm created events. | ||
* @returns Promise that resolves when the subscription is successful. | ||
*/ | ||
realmCreated() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.handleEvent('realmCreated'); | ||
}); | ||
} | ||
/** | ||
* Subscribes to realm destroyed events. | ||
* @returns Promise that resolves when the subscription is successful. | ||
*/ | ||
realmDestroyed() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.handleEvent('realmDestroyed'); | ||
}); | ||
} | ||
} |
@@ -9,2 +9,3 @@ import WebSocket from 'ws'; | ||
import Network from "./modules/network/commands"; | ||
import Script from "./modules/script/commands"; | ||
/** | ||
@@ -49,2 +50,2 @@ * BiDi class for handling WebSocket connections | ||
} | ||
export { BiDi, Browser, BrowsingContext, Input, Log, Network, Session, Storage }; | ||
export { BiDi, Browser, BrowsingContext, Input, Log, Network, Script, Session, Storage }; |
@@ -0,3 +1,3 @@ | ||
import { BrowsingContext } from "../browsingContext/types"; | ||
import { SharedReference } from "../script/types"; | ||
import { BrowsingContext } from "../browsingContext/types"; | ||
type InputOrigin = 'viewport' | 'pointer' | InputElementOrigin; | ||
@@ -4,0 +4,0 @@ type PointerType = "mouse" | "pen" | "touch"; |
import { BrowsingContext, Navigation } from "../browsingContext/types"; | ||
import { ScriptStackTrace } from "../script/types"; | ||
import { StackTrace } from "../script/types"; | ||
export type NetworkSameSite = 'strict' | 'lax' | 'none'; | ||
@@ -91,3 +91,3 @@ type NetworkIntercept = string; | ||
lineNumber?: number; | ||
stackTrace?: ScriptStackTrace; | ||
stackTrace?: StackTrace; | ||
request?: NetworkRequest; | ||
@@ -94,0 +94,0 @@ } |
{ | ||
"name": "wd-bidi", | ||
"version": "0.0.4-alpha-15", | ||
"version": "0.0.4-alpha-16", | ||
"description": "WebDriver BiDi API for automation testing", | ||
@@ -43,8 +43,8 @@ "main": "./build/cjs/index.js", | ||
"@eslint/js": "^9.8.0", | ||
"@types/node": "^20.14.12", | ||
"@types/ws": "^8.5.11", | ||
"@types/node": "^20.14.14", | ||
"@types/ws": "^8.5.12", | ||
"@typescript-eslint/eslint-plugin": "^7.17.0", | ||
"@typescript-eslint/parser": "^7.17.0", | ||
"eslint": "^8.57.0 ", | ||
"globals": "^15.8.0", | ||
"globals": "^15.9.0", | ||
"rimraf": "^6.0.1", | ||
@@ -51,0 +51,0 @@ "typedoc": "^0.26.5", |
196409
152
4873